Menu

#5 Libc bugs

open
None
5
2014-08-07
2005-01-04
Patsakh
No

Hello OSLib Team.

Here some bugs in your C library.

1. Character testing functions bugs:

isalpha('_') returns 1
iscntrl('!') returns 1
iscntrl(127) returns 0
isxdigit('?') returns 1
isnumber('?', 16) returns 1

In all these functions the argument must be an int.
The toupper and tolower functions must return an int.

2. The strncpy function must not append null character
to the copy in the array pointed to by dst, if the array
pointed to by src is longer than n characters or n is 0.

3. The strchr and strrchr functions must return a pointer
to the terminating null character of the string s, if the
char c is the null character.

4. The argument n in strncpy, strncmp, strncat functions
must have the type size_t, i.e. unsigned integral type.
The strlen function must return a value of type size_t.

5. The strcat and strchr functions must have constant
values as its input arguments.

Patsakh

Discussion

  • Luca Abeni

    Luca Abeni - 2005-01-12
    • assigned_to: nobody --> lucabe
     
  • Luca Abeni

    Luca Abeni - 2005-01-19

    Logged In: YES
    user_id=98577

    Hi,

    again, thanks for the bug report.
    I think I just fixed some of the bugs (but I had no time to
    test the correctness of some changes) - basically, I did not
    address the bugs related to the parameters' type: I want to
    think more about the problem (for example, since we only
    support ascii characters, does it make sense to use an int
    for a character?).

    Thanks,
    Luca

     
  • Patsakh

    Patsakh - 2005-01-21

    Logged In: YES
    user_id=1098150

    The standard requires that all character handling functions
    (is...() and to...()) correctly work with the value of the
    macro EOF, which expands to an integral expression. These
    functions therefore use int instead of char.

    I'll test your changes and report results in next message.

    Patsakh

     
  • Patsakh

    Patsakh - 2005-01-29

    Logged In: YES
    user_id=1098150

    The iscntrl function (from oslib\libc\string\strbase.c) is
    not changed. You can try to use this:

    return (c >= '\x00' && c <= '\x1F') || c == '\x7F';

    The isnumber function (from oslib\libc\string\strnum.c)
    works not correctly. You can try to use this:

    if(base < 2 || base > 16)
    return 0;

    if(base <= 10)
    return c >= '0' && c <= '0' + base - 1;
    else
    return (c >= '0' && c <= '9')
    || (c >= 'A' && c <= 'A' + base - 11)
    || (c >= 'a' && c <= 'a' + base - 11);

    You needed to replace all occurrences of "c" with "(char)c"
    in the strchr (from oslib\libc\string\string.c) and strrchr
    (from oslib\libc\string\strrchr.c) functions.

    Patsakh

     
  • Luca Abeni

    Luca Abeni - 2005-02-02

    Logged In: YES
    user_id=98577

    Hi,

    I found a typo in my modifications to isnumber(), and fixed
    it. It should now work correctly. I also modified iscntrl()
    to recognize DEL (I was under the impression that iscntrl()
    should return 1 only for control characters ;-).

    I think that the correct solution for strchr() & c would be
    to modify the prototype so that "c" is a char. In fact,
    oslib does not handle EOF (and EOF is not defined in oslib
    headers, I hope), so characters can just be of type char
    instead of int... Anyway, I want to think a little bit more
    before committing this change to strchr().

    Thanks,
    Luca

     
  • Patsakh

    Patsakh - 2005-02-05

    Logged In: YES
    user_id=1098150

    The iscntrl function does not work correctly (returns 1) if
    c is 0x80 to 0xFF (since, by default, char is signed).

    EOF is not defined in OSLib headers, but EOF may be defined
    in OS, which will be implemented with the help of the OSLib
    (AFAIK, OSLib is developed for this aim). The OSLib Manual
    declares that libc is a subset of the _standard_ C library.
    Therefore you should use standard prototypes. Anyway, using
    the standard names for nonstandard functions is bad choice.
    You may use private names (for example, oslib_iscntrl,
    osl_iscntrl or _iscntrl).

    If you decide to use nonstandard versions of functions, you
    can close this bug report.

    Patsakh

     
  • Patsakh

    Patsakh - 2005-02-22

    Logged In: YES
    user_id=1098150

    What have you decided?

     
  • Luca Abeni

    Luca Abeni - 2005-02-26

    Logged In: YES
    user_id=98577

    Hi;
    sorry for the late reply...
    I apologize for the isnctrl() bug: I wanted to commit a fix,
    but I was in hurry and I did not fully test it. I'll commit
    a better fix in the next days.

    Unfortunately, I have no time for dealing with your other
    concerns... I'll leave the bug open hoping to have more time
    in the future.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.