pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #15229: Crash when using PQgetvalue
3+ messages / 2 participants
[nested] [flat]
* BUG #15229: Crash when using PQgetvalue
@ 2018-06-04 16:28 PG Bug reporting form <noreply@postgresql.org>
0 siblings, 1 reply; 3+ messages in thread
From: PG Bug reporting form @ 2018-06-04 16:28 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: duncan.reitboeck@gmail.com
The following bug has been logged on the website:
Bug reference: 15229
Logged by: Duncan
Email address: duncan.reitboeck@gmail.com
PostgreSQL version: 10.4
Operating system: Windows 10
Description:
I am getting a segmentation fault in the below code when attempting to use
PQgetvalue. I am not 100 percent this is a bug and not a problem on my end
but I have done a lot of debugging and not found an answer.
PGconn *con;
PGresult *pg_result;
int i = 0;
int j = 0;
int cols = 0;
int rows = 0;
con = PQconnectdb("host=localhost user=postgres password=test
dbname=test");
if(PQstatus(con) != CONNECTION_OK)
{
printf("Could not connect to PostgreSQL database!");
fflush(stdout);
}
else
{
g_print("Connected.\n");
pg_result = PQexec(con, "SELECT * FROM test");
if(PQresultStatus(pg_result) == PGRES_TUPLES_OK)
{
rows = PQntuples(pg_result);
cols = PQnfields(pg_result);
for(i = 0; i < rows; ++i)
{
for(j = 0; j < cols; ++j)
{
printf("Row: %d - Col: %d = %s\n", i, j, PQgetvalue(pg_result, i,
j));
fflush(stdout);
}
}
}
PQclear(pg_result);
close_pgsql(con);
}
Some of the things I have tried debugging with:
1. Replacing PQgetvalue with PQgetlength.
The correct number of rows and fields are returned and the correct
length is printed for each.
2. Removing printf and simply calling function.
Still crashed at same location.
3. Checking PQgetisnull.
No null returned.
4. Different databases, connections, etc.
Always still crashed when trying to access PQgetvalue.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #15229: Crash when using PQgetvalue
@ 2018-06-04 16:55 Tom Lane <tgl@sss.pgh.pa.us>
parent: PG Bug reporting form <noreply@postgresql.org>
0 siblings, 1 reply; 3+ messages in thread
From: Tom Lane @ 2018-06-04 16:55 UTC (permalink / raw)
To: duncan.reitboeck@gmail.com; +Cc: pgsql-bugs@lists.postgresql.org
=?utf-8?q?PG_Bug_reporting_form?= <noreply@postgresql.org> writes:
> I am getting a segmentation fault in the below code when attempting to use
> PQgetvalue. I am not 100 percent this is a bug and not a problem on my end
> but I have done a lot of debugging and not found an answer.
Strange. Your code looks fine by eye, and just to be sure I
copied-and-pasted it and ran it here. No problems.
A couple of theories that could maybe account for the facts are
(1) corrupted copy of libpq.dll ... where did you get that from?
(2) somewhere earlier in your program, there are macro definitions
causing misinterpretation of rows/cols/PQgetvalue.
PQgetvalue does range-check its arguments, so it's hard to see how it
could crash internally, but maybe somehow it's handing back a NULL and
that's crashing printf?
Another idea is that if PQgetvalue does somehow think the arguments
are out of range, it will try to print a warning to stderr, and
I'v heard of that crashing on Windows. We'd still be left trying
to explain why it thinks the arguments are out of range, but that
would narrow down the problem.
Can you get a stack trace to identify exactly where the crash is?
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #15229: Crash when using PQgetvalue
@ 2018-06-04 19:56 Tom Lane <tgl@sss.pgh.pa.us>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 3+ messages in thread
From: Tom Lane @ 2018-06-04 19:56 UTC (permalink / raw)
To: duncan.reitboeck@gmail.com; +Cc: pgsql-bugs@lists.postgresql.org
I wrote:
> =?utf-8?q?PG_Bug_reporting_form?= <noreply@postgresql.org> writes:
>> I am getting a segmentation fault in the below code when attempting to use
>> PQgetvalue. I am not 100 percent this is a bug and not a problem on my end
>> but I have done a lot of debugging and not found an answer.
> Strange. Your code looks fine by eye, and just to be sure I
> copied-and-pasted it and ran it here. No problems.
Just to close out this thread --- the submitter reports the problem
went away after reinstalling libpq, so apparently "broken libpq"
was the correct diagnosis.
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2018-06-04 19:56 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-06-04 16:28 BUG #15229: Crash when using PQgetvalue PG Bug reporting form <noreply@postgresql.org>
2018-06-04 16:55 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-06-04 19:56 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox