PR libc/4755: Invalid code, not a bug
Petter Reinholdtsen
pere@hungry.com
Tue Apr 15 20:38:00 GMT 2003
The code in problem report 4755, "toupper(-1) == -1 for CP1251 charset
(-1 is cyrillic character 'ya'.", is invalid. The code looks like this:
#include <locale.h>
#include <ctype.h>
#include <stdio.h>
int main ()
{
int i, j;
setlocale (LC_ALL, "ru_RU.CP1251");
i = toupper (-1);
j = toupper (255);
printf ("%i/%c %i/%c\n", i, i, j, j);
}
This prints '-1/ÿ 223/Ã' when I test it.
My manual page lists the following prototype for toupper():
int toupper(int c);
It even mentions the use of signed values as c:
If c is not an unsigned char value, or EOF, the behaviour of these
functions is undefined.
I belive using '-1' as the argument to toupper() is undefined. It is
not supposed to behave as if -1 equals 255. If I change the
problematic line to this, the output is '223/Ã 223/Ã':
i = toupper ((unsigned char)-1);
I believe the code in question is invalid, as it uses signed values in
toupper efen if the manual page documents that this is undefined, and
that the problem report should be closed with 'not a bug' or 'invalid'
or some equivalent code in gnats.
More information about the Libc-alpha
mailing list