Unix Technical Forum

C locale, empty strings literals and NULL pointers on 5.3

This is a discussion on C locale, empty strings literals and NULL pointers on 5.3 within the AIX Operating System forums, part of the Unix Operating Systems category; --> When using localeconv() for the C locale, the lconv structure that it returns a pointer to contains several NULL ...


Go Back   Unix Technical Forum > Unix Operating Systems > AIX Operating System

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-05-2008, 10:56 AM
Hans Rosenfeld
 
Posts: n/a
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-05-2008, 10:56 AM
=?ISO-8859-2?Q?L=F5rinczy_Zsigmond?=
 
Posts: n/a
Default 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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-05-2008, 10:59 AM
Gary R. Hook
 
Posts: n/a
Default 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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:28 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com