Search Postgresql Archives

Re: Problem with using snprintf in C-function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ilya Urikh <ilya.urikh@xxxxxxxxx> writes:
> This code I wrote for PostgreSQL 8.3.7 on Fedora 10 and it worked fine. But
> now I use CentOS 5.3 and PostgreSQL 8.3.8.

It looks to me like you're assuming that %ld is the appropriate format
string for an int64 value.  This might be true on a 64-bit machine but
it would not be on 32-bit.  It's not obvious why that would lead to
exactly the results you show, but it could certainly account for
snprintf fetching the wrong bits for some of its arguments.

The portable way (within Postgres code) is to use INT64_FORMAT, which
will be set up correctly by configure.  So instead of

>              WHERE  accountId = %ld AND\

you need

               WHERE  accountId = " INT64_FORMAT " AND\

(relying on concatenation of literals in C).

BTW, if your compiler didn't warn you about this, you need to get a
new compiler, or at least start using the switches that would make it
warn you.  If you did get a warning, and ignored it, you need to
learn better habits ;-)

			regards, tom lane

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux