va_arg - Uninitialized call stack on Solaris 5.5.1

va_arg - Uninitialized call stack on Solaris 5.5.1

Post by Patricia Griffi » Tue, 12 May 1998 04:00:00


     I am having a problem with what looks like an uninitialized call stack on Solaris 5.5.1 while
     using a variable argument list function.   An example program is at the end of this message.
     The program was compiled with g++.

     Incorrectly, both finalArray1 and finalArray2 receive the string "Hello".  When I debugged it,
     I found the second invocation of bundle_args was picking up the stack variables
     from the previous call.

     When I compiled and ran this on an hpux10 machine, it worked correctly.

     Anyone seen this before?  If so, any work-arounds?  (I can pass "0" as a third parameter, but
     this is kind of kludgy).


     Pat Griffin

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

char **
bundle_args(char *header, int iter, ...)
   va_list listPtr = NULL;

   int i = 0;
   int num = 0;

   char **charArray = NULL;
   char **arrayPtr = NULL;
   char *arg = NULL;

   va_start(listPtr, iter);

   num = va_arg(listPtr, int);
   if (num)
      charArray = (char **)calloc(num + 1, sizeof(char *));
      arrayPtr = charArray;

      printf ("%s, iteration %d\n", header, iter);

      for (i = 0; i < num; i++)
  arg = va_arg(listPtr, char *);
  *arrayPtr = (char *)malloc(strlen(arg) + 1);
         strcpy(*arrayPtr, arg);
      *arrayPtr = NULL;


   char name1[] = "Hello";

   char **finalArray = NULL;
   char **finalArray2 = NULL;

   char **finalPtr = NULL;

   finalArray = bundle_args("We are in bundle_args", 1, 1,
   finalArray2 = bundle_args("We are in bundle_args", 2);

   finalPtr = finalArray;
   while (*finalPtr != NULL)
      printf("%s ", *finalPtr++);

   finalPtr = finalArray2;
   while (*finalPtr != NULL)
      printf("%s ", *finalPtr++);



1. call stack backtrace from a C program (Solaris)

I'm trying to get a call stack trace in a C program
under Solaris 2.6 or later.  Does anyone know how
to do it?

The info I'm looking for would be similar to this:
(10)  0x00045e08  integ + 0x408  [./two_brn.e]
(11)  0x0006468c  trajcem + 0x128  [./two_brn.e]
(12)  0x00055490  fly_traj + 0xf58  [./two_brn.e]
(13)  0x0004052c  top_level + 0x14  [./two_brn.e]
(14)  0x000567e4  _start + 0x34  [./two_brn.e]

which shows what the code was doing when it dies.

Under HP-UX and IRIX, a printout like the above can
be obtained by calling U_STACK_TRACE() and
trace_back_stack_and_print(), respectively.



Sent via

2. Sunray Server 1.3 question

3. va_arg in solaris (mush,xv)

4. SLIPLOGIN - Helo MCalling in wtrhith Trumpet WinSock

5. demystifying process stack vs. java thread stack on solaris

6. NEC 3XP portable CD-ROM?

7. Call Stack for Apache

8. NIS+ ": " separator problem in cred table

9. Examining the calling stack in C

10. application call stack on SPARC v9

11. how to print the call stack of a thread

12. accessing call stack and symbol table

13. Showing the 'call stack'