C locale, empty strings literals and NULL pointers on 5.3 - Aix

This is a discussion on C locale, empty strings literals and NULL pointers on 5.3 - Aix ; When using localeconv() for the C locale, the lconv structure that it returns a pointer to contains several NULL pointers where I would have expected it to contain pointers to empty strings or string literals. As far as I understand ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: C locale, empty strings literals and NULL pointers on 5.3

  1. C locale, empty strings literals and NULL pointers on 5.3

    When using localeconv() for the C locale, the lconv structure that it
    returns a pointer to contains several NULL pointers where I would have
    expected it to contain pointers to empty strings or string literals.

    As far as I understand this works because *(char *)NULL is readable and
    contains '\0', so technically these pointers aren't NULL pointers but
    pointers to empty strings that just happen to be at the exact same
    location that NULL points to.

    The code later tries to strdup() one of these strings (lconv->grouping),
    but strdup((char *) 0) will return NULL, which according to the manual
    indicates that it could not allocate the buffer for the new string.

    I have no idea what exactly is going on here, but I think it could be a
    bug in the C library (using NULL instead of empty string literals, or
    not allowing NULL pointers as source arguments in the string functions).

    The only workaround I have found so far is not using the C locale but
    en_US or something else.

    Any hints what to do about this? Am I missing something here?


    --
    %SYSTEM-F-ANARCHISM, The operating system has been overthrown

  2. Re: C locale, empty strings literals and NULL pointers on 5.3

    Hans Rosenfeld wrote:
    > When using localeconv() for the C locale, the lconv structure that it
    > returns a pointer to contains several NULL pointers where I would have
    > expected it to contain pointers to empty strings or string literals.
    >
    > As far as I understand this works because *(char *)NULL is readable and
    > contains '\0', so technically these pointers aren't NULL pointers but
    > pointers to empty strings that just happen to be at the exact same
    > location that NULL points to.
    >
    > The code later tries to strdup() one of these strings (lconv->grouping),
    > but strdup((char *) 0) will return NULL, which according to the manual
    > indicates that it could not allocate the buffer for the new string.
    >
    > I have no idea what exactly is going on here, but I think it could be a
    > bug in the C library (using NULL instead of empty string literals, or
    > not allowing NULL pointers as source arguments in the string functions).
    >
    > The only workaround I have found so far is not using the C locale but
    > en_US or something else.
    >
    > Any hints what to do about this? Am I missing something here?


    I'm using AIX 5.2L, and my every my tries gave the same result:
    functions setlocale and nl_langinfo are not working correctly.

  3. Re: C locale, empty strings literals and NULL pointers on 5.3

    Hans Rosenfeld wrote:
    > When using localeconv() for the C locale, the lconv structure that it
    > returns a pointer to contains several NULL pointers where I would have
    > expected it to contain pointers to empty strings or string literals.


    The documentation states that the pointes in the data structure may
    point to NULL strings. A NULL pointer could be interpreted as a bug.

    > As far as I understand this works because *(char *)NULL is readable and
    > contains '\0',


    This has nothing to do with whether page 0 in memory is readable. It
    has to do with the implementation of the code. While you might want to
    be checking that both 'foo' and '*foo' are non-zero, I'd suggest you
    report this as a defect.

+ Reply to Thread