pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: duncan.reitboeck@gmail.com
Subject: BUG #15229: Crash when using PQgetvalue
Date: Mon, 04 Jun 2018 16:28:15 +0000
Message-ID: <152812969559.26728.1109379398061677469@wrigleys.postgresql.org> (raw)

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.



view thread (3+ messages)  latest in thread

Message-ID: <152812969559.26728.1109379398061677469@wrigleys.postgresql.org>
Permalink:  ../152812969559.26728.1109379398061677469@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/152812969559.26728.1109379398061677469@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, duncan.reitboeck@gmail.com
  Subject: Re: BUG #15229: Crash when using PQgetvalue
  In-Reply-To: <152812969559.26728.1109379398061677469@wrigleys.postgresql.org>
  References: <152812969559.26728.1109379398061677469@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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