On AIX 6.1, I have a piece of code where the argv
is getting set to NULL
somehow after a call to strdup
. The exact same code was working on Linux, HPUX and Solaris.
Here's the excerpt from production code where I am getting core dump:
Makefile
....
CFLAGS += -I$(SERVER)/shared/interfaces \
-DADAPTER_BUILD_DATE="\"$(shell date)\""
....
global.c
...
char *z_adapter_build_date = NULL;
...
shared.c
...
extern char *z_adapter_build_date;
...
test.c
int main(int l_argc, char **l_argv)
{
char *lbasename;
char *ltmp;
z_adapter_build_date = (char *)ADAPTER_BUILD_DATE;
ltmp = strdup(l_argv[0]);
lbasename = basename(ltmp);
if ((zprogname = strdup(lbasename)) == NULL)
{
printf("strdup failed:\n");
exit(1);
}
....
$ dbx ./test
warning: tpm_builtin_fn.cc is newer than /xps/ceal_800/rel/server/lib/libsql.so
warning: trans_tux.cc is newer than /xps/ceal_800/rel/server/lib/libsql.so
warning: varmap.cc is newer than /xps/ceal_800/rel/server/lib/libsql.so
(dbx) [1] stop in main
(dbx)
(dbx) r 1
[1] stopped in main at line 113 in file "/u01/xps/800/src/test.c" ($t1)
113 z_adapter_build_date = (char *)ADAPTER_BUILD_DATE;
(dbx) p l_argv[1]
"1"
(dbx) n
stopped in main at line 115 in file "/u01/xps/800/src/test.c" ($t1)
115 ltmp = strdup(l_argv[0]);
(dbx) p l_argv[1]
(nil)
However, may be a red herring, there are mismatches in the version of cc files above which I guess could be one reason. I am not quite sure what is causing the value to become NULL.