crash when using va_list, va_arg | developer.brewmp.com crash when using va_list, va_arg | developer.brewmp.com

Developer

crash when using va_list, va_arg

Forums:

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px 'Courier New'}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px 'Courier New'; min-height: 11.0px}

Hi

 

I am using BREW 3.1.5

 

The following function crashes in Simulator. 

 

void MYFUNCTION(const char *fmt, ...)

{

 char *buf = (char*)MALLOC(200);

 int nbChar = 0;

 char tmp[10];

 va_list ap;

 va_start(ap, fmt);

 //asprintf (&buf, fmt, ap);

 //nbChar = SNPRINTF(NULL, 0, fmt, &tmp, __FILE__, __LINE__, 23, "ZZZZZZZZZZ"); 

 nbChar = SNPRINTF(NULL, 0, fmt, ap); 

 

 buf = MALLOC(nbChar);

 

 //nbChar = SNPRINTF(buf, nbChar, fmt, &tmp, __FILE__, __LINE__, 23, "ZZZZZZZZZZ"); 

 nbChar = SNPRINTF(buf, nbChar, fmt, ap); 

 

 va_end(ap);

 DBGPRINTF(buf);

 FREEIF(buf);

}

Crash is here (see ==>)

 

 nbChar = SNPRINTF(NULL, 0, fmt, ap); 

02951C7B  mov         esi,esp  

02951C7D  mov         ecx,dword ptr [ap]  

02951C80  push        ecx  

02951C81  mov         edx,dword ptr [fmt]  

02951C84  push        edx  

02951C85  push        0  

02951C87  push        0  

02951C89  mov         eax,dword ptr [_g_pvtAEEStdLibEntry (29DAF48h)]  

02951C8E  call        dword ptr [eax+144h]  

==> 02951C94  add         esp,10h  

02951C97  cmp         esi,esp  

02951C99  call        __chkesp (2957230h)  

02951C9E  mov         dword ptr [nbChar],eax  

 

 buf = MALLOC(nbChar);

02

 

I would appreciate any help

 

Thank you!

 

You can't use va_args with snprintf, that's what vsnprintf() is for  :)

You can't use va_args with snprintf, that's what vsnprintf() is for  :)