SEGV while working with va_list
![](https://seccdn.libravatar.org/avatar/772c7e8e017da63e4e988e8229a40789.jpg?s=120&d=mm&r=g)
Hi, The following program crashes on suse-ppc. I am trying to copy the command line parameters to a string buffer. I tried this on suse i386 and its working fine. Its crashing on suse-ppc. #include <stdio.h> #include <stdarg.h> main(int argc, char *argv[]) { char Buffer[1024]; va_list ap; //ap = argv; //works fine on i386 va_copy(ap,argv); // cant use ap = argv on ppc. Need to use va_copy vsprintf(Buffer,"Command Line arguments: %s\n",ap); printf("%s", Buffer); } Please help me in resolving this. Thank you, Appy.
![](https://seccdn.libravatar.org/avatar/bff0c215e01f23fcee6fe49e65fae458.jpg?s=120&d=mm&r=g)
On Mon, Oct 30, 2006 at 01:24:35AM -0800, appy 80 wrote:
Hi,
The following program crashes on suse-ppc. I am trying to copy the command line parameters to a string buffer. I tried this on suse i386 and its working fine. Its crashing on suse-ppc.
#include <stdio.h> #include <stdarg.h>
main(int argc, char *argv[]) { char Buffer[1024]; va_list ap; //ap = argv; //works fine on i386 va_copy(ap,argv); // cant use ap = argv on ppc. Need to use va_copy vsprintf(Buffer,"Command Line arguments: %s\n",ap); printf("%s", Buffer); }
Please help me in resolving this.
The argv array is not a variable argument list. You will have to use a for(i=1;i<argc;i++) { ... print argv[i] ... } loop. Ciao, Marcus
![](https://seccdn.libravatar.org/avatar/772c7e8e017da63e4e988e8229a40789.jpg?s=120&d=mm&r=g)
Hi, This code is just a sample code that I have written to illustrate the problem. I need to convert the command line arguments into a va_list. I tried using "ap =argv;". But this is not allowed on ppc. So I am using "va_copy" to copy the contents of argv into ap. This is the main purpose. However when I use ap with vsprintf, the application is crashing. Thanks, Appy. Marcus Meissner <meissner@suse.de> wrote: On Mon, Oct 30, 2006 at 01:24:35AM -0800, appy 80 wrote:
Hi,
The following program crashes on suse-ppc. I am trying to copy the command line parameters to a string buffer. I tried this on suse i386 and its working fine. Its crashing on suse-ppc.
#include #include
main(int argc, char *argv[]) { char Buffer[1024]; va_list ap; //ap = argv; //works fine on i386 va_copy(ap,argv); // cant use ap = argv on ppc. Need to use va_copy vsprintf(Buffer,"Command Line arguments: %s\n",ap); printf("%s", Buffer); }
Please help me in resolving this.
The argv array is not a variable argument list. You will have to use a for(i=1;i Ciao, Marcus --------------------------------- Want to start your own business? Learn how on Yahoo! Small Business.
![](https://seccdn.libravatar.org/avatar/f1da0a8043ee559cc23eb836ec821f60.jpg?s=120&d=mm&r=g)
On Mon, Oct 30, appy 80 wrote:
This code is just a sample code that I have written to illustrate the problem. I need to convert the command line arguments into a va_list. I tried using "ap =argv;". But this is not allowed on ppc. So I am using "va_copy" to copy the contents of argv into ap. This is the main purpose. However when I use ap with vsprintf, the application is crashing.
Please provide a real usable example hello_world.c There is nothing wrong with va_args, unless proven otherwise.
![](https://seccdn.libravatar.org/avatar/bff0c215e01f23fcee6fe49e65fae458.jpg?s=120&d=mm&r=g)
On Mon, Oct 30, 2006 at 02:27:54AM -0800, appy 80 wrote:
Hi,
This code is just a sample code that I have written to illustrate the problem. I need to convert the command line arguments into a va_list. I tried using "ap =argv;". But this is not allowed on ppc. So I am using "va_copy" to copy the contents of argv into ap. This is the main purpose. However when I use ap with vsprintf, the application is crashing.
I am afraid it is not possible. va_list are created by the compiler on a varargs function call, you cannot do it programmaticaly. Ciao, Marcus
![](https://seccdn.libravatar.org/avatar/772c7e8e017da63e4e988e8229a40789.jpg?s=120&d=mm&r=g)
Thanks Marcus, Appy. Marcus Meissner <meissner@suse.de> wrote: On Mon, Oct 30, 2006 at 02:27:54AM -0800, appy 80 wrote:
Hi,
This code is just a sample code that I have written to illustrate the problem. I need to convert the command line arguments into a va_list. I tried using "ap =argv;". But this is not allowed on ppc. So I am using "va_copy" to copy the contents of argv into ap. This is the main purpose. However when I use ap with vsprintf, the application is crashing.
I am afraid it is not possible. va_list are created by the compiler on a varargs function call, you cannot do it programmaticaly. Ciao, Marcus --------------------------------- Want to start your own business? Learn how on Yahoo! Small Business.
participants (3)
-
appy 80
-
Marcus Meissner
-
Olaf Hering