- 论坛徽章:
- 0
|
越界了,
char * message = alloca( 1024 * strlen(fmt) + 1);
- #include <stdio.h>
- #include <stdarg.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <stdlib.h>
- void t_var_argu(char * fmt,...);
- int main(void)
- {
- printf("test variable parameters.\n\n");
- char *env;
- env=getenv("PATH");
- if(env==NULL)
- {
- t_var_argu("current pid:%ld,get the environment failure.\n",getpid());
- return -1;
- }
- sleep(0.5);
- t_var_argu("current pid:%ld,get the environment:%s success.\n",getpid(),env);
- return 0;
- }
- void t_var_argu(char * fmt,...)
- {
- va_list arg_ptr;
- [color=Red]char * message = alloca( 1024 * strlen(fmt) + 1);[/color]
- va_start(arg_ptr,fmt); /*to direct a variable argument type point */
- vsprintf(message,fmt,arg_ptr); /* convert to string and copy into message */
- va_end(arg_ptr);
- printf("%s",message);
- }
复制代码
[ 本帖最后由 lonelyair 于 2006-9-13 19:07 编辑 ] |
|