Error in PQsetvalue

Поиск
Список
Период
Сортировка
От Pavel Golub
Тема Error in PQsetvalue
Дата
Msg-id BANLkTin0aB=mr5YvBraPufLB11cJh6nALw@mail.gmail.com
обсуждение исходный текст
Ответы Re: Error in PQsetvalue  (Andrew Chernow <ac@esilo.com>)
Re: Error in PQsetvalue  (Merlin Moncure <mmoncure@gmail.com>)
Список pgsql-hackers
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 */{    fprintf(stderr, "Shit happens: %s", PQerrorMessage(conn));    exit_nicely(conn);}
   PQclear(res);   PQfinish(conn);   return 0;
}

BUT! If we change direct call to:

...       res = PQexec(conn, "SELECT generate_series(1, 10)");
res2 = PQcopyResult(res, PG_COPYRES_TUPLES);
if (!PQsetvalue(res2, PQntuples(res), 0, "1", 1)){    fprintf(stderr, "Shit happens: %s", PQerrorMessage(conn));
exit_nicely(conn);}
...
then all is OK!

As you can see, I copied result first. No error occurs.
Can anybody check this on other platforms?
-- 
Nullus est in vitae sensus ipsa vera est sensus.


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Domains versus polymorphic functions, redux
Следующее
От: "Kevin Grittner"
Дата:
Сообщение: Re: SIREAD lock versus ACCESS EXCLUSIVE lock