Hello, 

First, I'll show the warnings seen when compiling postgres on 
SunOS 5.6 with gcc 3.2.1

copy.c: In function `GetDecimalFromHex':
copy.c:2660: warning: subscript has type `char'
copy.c: In function `CopyReadAttributesText':
copy.c:2805: warning: subscript has type `char'
copy.c:2813: warning: subscript has type `char'

Actually this warnings are caused by the isdigit function.
On Solaris systems, isdigit is organized as an array lookup, so all the 
arguments should be casted to unsigned char. 

2660c2660
<       if (isdigit(hex))
---
>       if (isdigit((unsigned char)hex))
2805c2805
<                                                       if (isxdigit(hexchar))
---
>                                                       if (isxdigit((unsigned 
> char)hexchar))
2813c2813
<                                                                       if 
(isxdigit(hexchar))
---
>                                                                       if 
> (isxdigit((unsigned char)hexchar))



Actually that problem cause not only warnings but real bugs too,
exploiting that problem. (when the char >128 and is not casted to 
unsigned, on  solaris there will be a negative indices of arrays)

For example on SunOS (or any Solaris):

test=# CREATE TABLE test0 (xx char(2));
CREATE TABLE
test=# copy test0 from stdin;
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> \x3п
>> \.
test=# select length(xx) from test0;
 length 
--------
      1
(1 row)


But on NOT Solaris: 

test=# CREATE TABLE test0 (xx char(2));
CREATE TABLE
test=# copy test0 from stdin;
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> \x3п
>> \.
test=# select length(xx) from test0;
 length 
--------
      2
(1 row)


I'm not sure that everybody will see that code properly due to encoding 
differences. But the idea is just feed postgres with "\x3" and one 
character with the code >128. 



Regards,
        Sergey

*****************************************************
Sergey E. Koposov
Max-Planck Institut fuer Astronomie
Web: http://lnfm1.sai.msu.ru/~math 
E-mail: [EMAIL PROTECTED]

--- src/backend/commands/copy.c.orig    2005-09-01 15:07:01.000000000 +0200
+++ src/backend/commands/copy.c 2005-09-01 15:08:45.000000000 +0200
@@ -2657,7 +2657,7 @@
 static int
 GetDecimalFromHex(char hex)
 {
-       if (isdigit(hex))
+       if (isdigit((unsigned char)hex))
                return hex - '0';
        else
                return tolower(hex) - 'a' + 10;
@@ -2802,7 +2802,7 @@
                                                {
                                                        char hexchar = *cur_ptr;
 
-                                                       if (isxdigit(hexchar))
+                                                       if (isxdigit((unsigned 
char)hexchar))
                                                        {
                                                                int val = 
GetDecimalFromHex(hexchar);
 
@@ -2810,7 +2810,7 @@
                                                                if (cur_ptr < 
line_end_ptr)
                                                                {
                                                                        hexchar 
= *cur_ptr;
-                                                                       if 
(isxdigit(hexchar))
+                                                                       if 
(isxdigit((unsigned char)hexchar))
                                                                        {
                                                                                
cur_ptr++;
                                                                                
val = (val << 4) + GetDecimalFromHex(hexchar);
---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Reply via email to