This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
PR libc/4755: Invalid code, not a bug
- From: Petter Reinholdtsen <pere at hungry dot com>
- To: libc-alpha at sources dot redhat dot com
- Date: Tue, 15 Apr 2003 22:38:00 +0200
- Subject: PR libc/4755: Invalid code, not a bug
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.