8.1beta, Subtle bug in COPY in Solaris systems
От | Sergey E. Koposov |
---|---|
Тема | 8.1beta, Subtle bug in COPY in Solaris systems |
Дата | |
Msg-id | Pine.LNX.4.44.0509011700300.3163-200000@lnfm1.sai.msu.ru обсуждение исходный текст |
Ответы |
Re: 8.1beta, Subtle bug in COPY in Solaris systems
|
Список | pgsql-hackers |
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: math@sai.msu.ru
В списке pgsql-hackers по дате отправления: