I recently received an rt (https://rt.cpan.org/Ticket/Display.html?id=79190) 
saying some code in DBD::ODBC was wrong and a patch to fix it. The code was:

   while (*cp != '\0') {
      *cp++ = toupper(*cp);
   }

and the fix (which shouldn't be required as the above code is fine) was:

   while (*cp != '\0') {
      *cp = toupper(*cp);
      cp++;
   }

When I provided some test code and asked the reporter to tell me the compiler 
he reported a load of gcc versions which when using -O (above 0) produce 
incorrect results.

The test code and his results are below. I can obviously avoid this issue with 
a simple change to the code but how many other places might this occur? Do I 
ignore this (as the reporter is happy to use a newer working compiler) or do I 
somehow check for a broken compiler and abort the Makefile? Has anyone else 
come across something like this and what did they do?

#include <stdio.h>
#include <ctype.h>
#include <string.h>
main() {
    char f[20];
    char *cp;
    strcpy(f, "abcdefg");
    cp = f;
    while(*cp != '\0') {
        *cp++ = toupper(*cp);
    }
    printf("%s\n", f);
}

and his results:

Here are my results (gcc version, optimalization, program output):
3.2 -O0 ABCDEFG
3.2 -O1 BCDEFG
3.2 -O2 BCDEFG
3.2 -O3 BCDEFG
3.4 -O0 ABCDEFG
3.4 -O1 BCDEFG
3.4 -O2 BCDEFG
3.4 -O3 BCDEFG
4.1 -O0 ABCDEFG
4.1 -O1 ABCDEFG
4.1 -O2 ABCDEFG
4.1 -O3 ABCDEFG
4.7.1 -O0 ABCDEFG
4.7.1 -O1 ABCDEFG
4.7.1 -O2 ABCDEFG
4.7.1 -O3 ABCDEFG

Martin
--
Martin J. Evans
Easysoft Limited
http://www.easysoft.com

Reply via email to