This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
GCC char* bug
- To: GCC-Bugs <gcc-bugs at gcc dot gnu dot org>
- Subject: GCC char* bug
- From: Bruce Korb <bkorb at pacbell dot net>
- Date: Fri, 20 Jul 2001 20:58:22 -0700
- Cc: Raúl Núñez de Arenas Coronado<dervishd at jazzfree dot com>
- Organization: Home
When the input character is 0xF5 and char is signed,
the following code fails to compare equal:
1257 static void test_for_changes PARAMS ((int));
1258 static void
1259 test_for_changes (read_fd)
1260 int read_fd;
- 1261 {
- 1262 FILE *in_fp = fdopen (read_fd, "r");
- 1263 FILE *out_fp = (FILE *) NULL;
- 1264 char *pz_cmp = pz_curr_data;
1265
unsigned char *pz_cmp = (unsigned char*)pz_curr_data;
1266 #ifdef DO_STATS
1267 fixed_ct++;
1268 #endif
- 1269 for (;;)
1270 {
- 1271 int ch;
1272
- 1273 ch = getc (in_fp);
- 1274 if (ch == EOF)
- 1275 break;
1276
ch &= 0xFF; /* bytes will only ever be 8 bits */
1277 /* IF we are emitting the output
1278 THEN emit this character, too.
1279 */
- 1280 if (out_fp != (FILE *) NULL)
- 1281 putc (ch, out_fp);
1282
1283 /* ELSE if this character does not match the original,
1284 THEN now is the time to start the output.
1285 */
- 1286 else if (ch != *pz_cmp)
1287 {
1288 out_fp = create_file ();
Line 1286 compares "ch"(-10) with "*pz_cmp"(246) and says that they are
not equal. The workaround is obvious, but by golly chars
are either signed or they are not signed. If they are not
signed, then the compare should show equal. On the other
hand, if they *are* signed, then 0xF5 should compare equal
to 0xFFFFFFF5. You cannot just do it one way sometimes
and another way other times.