1833431 Members
3259 Online
110052 Solutions
New Discussion

SIGBUS in setlocale()

 
Radu Ux D.
New Member

SIGBUS in setlocale()

Hi

I have an application ported on Windows (2k, 2003), Solaris (9,10) and HPUX (11.i). The application crashes only on HPUX in setlocale() with SIGBUS.
The stack looks like:

#0 0x425160 in setlocale+0x84 ()
#1 0x2e52ac in get_charset (_charset=0x79c7c6a8
"\303z4\037\306\016\203c") at i18n.c:330
#2 0x478ff0 in CLIServer:mlch2ch::get_XMLTranscoder (this=0x79c7460c) at xmlch2ch.h:39
........................................................................................................

Of course, the higher frames than #0 are inside our code. The last code line is

crt_locale = strdup(setlocale(LC_CTYPE, NULL));

The linking command is:
aCC -Wl,+s -o -g0 -AA +DAportable -L. -L/usr/lib -L -mt -Wl,-a,shared -lpthread -lnsl -lxti -lm -lc -lxerces-c -Wl,-a,archive - -lssl -lcrypto

I have PHCO_33711 applied. Machine is
HP-UX hpux B.11.11 U 9000/785 2011252307 unlimited-user license

What is wrong?

Thank you in advance

Radu
6 REPLIES 6
Peter Godron
Honored Contributor

Re: SIGBUS in setlocale()

Radu,
please seperate the commands, which will give you a better idea exactly which one is failing (setlocale or strdup). I assume you have included the definitions for LC_CTYPE and NULL. crt_locale should be able to hold a pointer. Also, you didn't notice any memory problems, as malloc is being used by strdup?
Radu Ux D.
New Member

Re: SIGBUS in setlocale()

No, it definitely crashes in setlocale() (I also run in wdb, in addition to the fact that the stack is always pointing setlocale()).
No, I see no memory stress; the application is taking under 30MB in that moment.

The crash is not always reproducible, but always the stack is the same. Otherwise I would suppose a memory corruption somewhere.

I suspect that is also related to the build system. Building the application on other machine, it seems not to crash, although because it is intermittent I couldn't guarranty that.

Radu
Peter Godron
Honored Contributor

Re: SIGBUS in setlocale()

Radu,
from nman environ:
"For example, when invoked as
setlocale(LC_CTYPE, ""), setlocale() will query the
LC_CTYPE environment variable first to see if it is
set and non-null. If LC_CTYPE is not set or null, then
setlocale() will check the LANG environment variable
to see if it is set and non-null. If both LANG and
LC_CTYPE are unset or NULL, the default "C" locale
will be used to set the LC_CTYPE category."

Although this error is not always repeatable, it may be worthwhile checking your environment definitions ,such as LC_CTYPE, NULL etc. Are you getting clean compiles/links?
Radu Ux D.
New Member

Re: SIGBUS in setlocale()

Yeah, my both LANG and and LC_CTYPE envs are NULL. But as you say, this shouldn't SIGBUS, right?

Radu
p.s. about compiling, yes it is clear, except the horde of "Future Error" specific to aCC.
Sandman!
Honored Contributor

Re: SIGBUS in setlocale()

Hi Radu,

Change the call to setlocale and then re-compile:

FROM...
crt_locale = strdup(setlocale(LC_CTYPE, NULL));
TO...
crt_locale = strdup(setlocale(LC_CTYPE, ""));

cheers!
Radu Ux D.
New Member

Re: SIGBUS in setlocale()

Hi

I need to stick with NULL usage because it is returning locales set on process (these ones I need), not on system as using "". Am I wrong?

Radu