Subject: | Integer/datetime retrieval broken on sparc64 |
Perl v5.8.5 built for sparc64-freebsd
DBI::Pg version 1.32 (FreeBSD ports as of today, 02-Jan-2004)
PostgreSQL version 7.4.6 (FreeBSD ports as of today, 02-Jan-2004)
OS: FreeBSD 5.3-STABLE/sparc64
My FreeBSD 5.3-STABLE/sparc64 machine (A Sun Netra T1 105) gives blank strings for all integer and timedate fields (and probably more). This is due to an incorrect mixture of size_t and int, in quote.c and dbdimp.c.
Using the exact same versions of all software on a Pentium IV with FreeBSD 5.3-STABLE wields no problems. Using the Sun as server and the Pentium IV as client gives no problems.
Due to the 64 bit nature of the UltraSPARC family, casting from size_t to int and the other way around may wield incorrect values. The attached patch fixes the problems, and cleans quote.c to always use size_t for strings when needed.
diff -ru DBD-Pg-1.32.org/dbdimp.c DBD-Pg-1.32/dbdimp.c
--- DBD-Pg-1.32.org/dbdimp.c Sun Jan 2 20:01:43 2005
+++ DBD-Pg-1.32/dbdimp.c Sun Jan 2 20:06:16 2005
@@ -986,7 +986,9 @@
int num_fields;
char *value;
char *p;
- int i, pg_type, value_len, chopblanks, len;
+ int i, pg_type, chopblanks;
+ size_t value_len;
+ STRLEN len;
AV *av;
D_imp_dbh_from_sth;
diff -ru DBD-Pg-1.32.org/quote.c DBD-Pg-1.32/quote.c
--- DBD-Pg-1.32.org/quote.c Sun Jan 2 20:01:43 2005
+++ DBD-Pg-1.32/quote.c Sun Jan 2 20:04:39 2005
@@ -9,7 +9,7 @@
{
const char *source = from;
char *target = to;
- unsigned int remaining = length;
+ unsigned size_t remaining = length;
while (remaining > 0)
{
@@ -146,9 +146,9 @@
unsigned char *
PQunescapeBytea2(const unsigned char *strtext, size_t *retbuflen)
{
- size_t strtextlen, buflen;
+ size_t strtextlen, buflen, i, j;
unsigned char *buffer, *tmpbuf;
- int i, j, byte;
+ int byte;
if (strtext == NULL) {
return NULL;
@@ -393,7 +393,7 @@
{
char *result;
char *dest;
- int max_len = 0, i;
+ size_t max_len = 0, i;
/* We are going to retun a quote_bytea() for backwards compat but
we warn first */
@@ -483,7 +483,7 @@
void
dequote_char(string, retlen)
char *string;
- int *retlen;
+ size_t *retlen;
{
/* TODO: chop_blanks if requested */
*retlen = strlen(string);
@@ -493,7 +493,7 @@
void
dequote_varchar (string, retlen)
char *string;
- int *retlen;
+ size_t *retlen;
{
*retlen = strlen(string);
}
@@ -503,7 +503,7 @@
void
dequote_bytea(string, retlen)
char *string;
- int *retlen;
+ size_t *retlen;
{
char *s, *p;
int c1,c2,c3;
@@ -542,7 +542,7 @@
void
dequote_sql_binary (string, retlen)
char *string;
- int *retlen;
+ size_t *retlen;
{
/* We are going to retun a dequote_bytea(), JIC */
warn("Use of SQL_BINARY invalid in dequote()");
@@ -556,7 +556,7 @@
void
dequote_bool (string, retlen)
char *string;
- int *retlen;
+ size_t *retlen;
{
switch(*string){
case 'f': *string = '0'; break;