Re: Error in PQsetvalue

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Pavel Golub <pavel(at)microolap(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Error in PQsetvalue
Date: 2011-06-03 20:08:55
Message-ID: BANLkTi=9MhHDLJWO2-64TfcHhhRiuaFesw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jun 3, 2011 at 2:03 PM, Pavel Golub <pavel(at)microolap(dot)com> wrote:
> Hello.
>
> Reproduced under Windows XP SP3 using Visual C++ 2008 and Delphi. If
> PQsetvalue is called with second parameter equals to PQntuples then
> memory corruption appears. But it should grow internal tuples array
> and populate the last item with provided data. Please see the code:
>
>
> #include <stdio.h>
> #include <stdlib.h>
> #include "libpq-fe.h"
> #pragma comment(lib,"libpq.lib")
>
> static void
> exit_nicely(PGconn *conn)
> {
>    PQfinish(conn);
>    exit(1);
> }
>
> int
> main(int argc, char **argv)
> {
>    const char *conninfo;
>    PGconn     *conn;
>    PGresult   *res;
>    if (argc > 1)
>        conninfo = argv[1];
>    else
>        conninfo = "dbname = postgres user = postgres password = password";
>
>    conn = PQconnectdb(conninfo);
>
>    if (PQstatus(conn) != CONNECTION_OK)
>    {
>        fprintf(stderr, "Connection to database failed: %s", PQerrorMessage(conn));
>        exit_nicely(conn);
>    }
>
>   res = PQexec(conn, "SELECT generate_series(1, 10)");
>
>   if (!PQsetvalue(res, PQntuples(res), 0, "1", 1))   /* <----- here
> we have memory corruption */

hm, what are the exact symptoms you see that is causing you to think
you are having memory corruption? (your example is working for me).

merlin

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2011-06-03 20:09:00 Re: Change 'pg_ctl: no server running' Exit Status to 3
Previous Message Andrew Chernow 2011-06-03 20:06:47 Re: Error in PQsetvalue