Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#13 Test programs incorrectly assume signed chars

Judy-1.0.0
closed-fixed
nobody
None
5
2005-02-09
2004-10-04
Tom Payne
No

Symptom:

Test programs enter infinite loops on architectures
which use unsigned chars by default.

Cause:

Test programs include code like:

char c;

while ((c == getopt(...)) != -1) {
...
}

Since unsigned chars cannot represent -1, the loop
condition is always true and the while loop never
terminates.

Solution:

Store the return value of getopt in an int, not a char.
The attached patch fixes all test programs.

Discussion

  • Tom Payne
    Tom Payne
    2004-10-04

    Judy-getopt-unsigned-char.patch

     
  • Tom Payne
    Tom Payne
    2004-10-04

    Logged In: YES
    user_id=1131688

    Example erroneous code should be:

    char c;

    while ((c = getopt(...)) != -1) {
    ...
    }

    Change: =, not ==, in assignment in loop condition.

     
    • status: open --> pending
     
  • Logged In: YES
    user_id=558029

    Tom:

    Stupid me. I will fix at the next release of Judy or if
    something else comes up.

    Thanks for your inputs. I wonder what platform has a "char"
    as an unsigned char?

    Doug Baskins

     
  • Tom Payne
    Tom Payne
    2004-10-18

    • status: pending --> open
     
  • Tom Payne
    Tom Payne
    2004-10-18

    Logged In: YES
    user_id=1131688

    To my knowledge, the ARM and IBM S/390 architectures use
    unsigned chars by default, and maybe also HP-PA.

    Best regards,

    Tom

     
  • Troy Heber
    Troy Heber
    2005-02-09

    • status: open --> closed-fixed
     
  • Troy Heber
    Troy Heber
    2005-02-09

    Logged In: YES
    user_id=171898

    Will be fixed in next release.