EmbeddedRelated.com
Forums
Memfault Beyond the Launch

problem with vsnprintf

Started by smarini1963 January 7, 2010
I'm using crossworks for arm

Below there is a little example, in which vsnprintf
report wrong result.

someone can help me to understand what I wrong?
----- EXAMPLE--------
#include
#include
#include
#include

void testlog_snprintf(const char *fmt, ...)
{
va_list ap;
int len;
char bufMsg[50];

memset(bufMsg,0x00,sizeof(bufMsg));
len=0;
va_start(ap, fmt);
len=vsnprintf(bufMsg, sizeof(bufMsg), fmt, ap);
//vsprintf(bufMsg, fmt, ap);
int aa=0;
va_end(ap);
}

int main (void)
{

testlog_snprintf("test %d",10);

int aa=0;
return aa;
}

An Engineer's Guide to the LPC2100 Series

smarini1963 schrieb:
> I'm using crossworks for arm
>
> Below there is a little example, in which vsnprintf
> report wrong result.

Kind off ?

> someone can help me to understand what I wrong?
> ----- EXAMPLE--------
> #include
> #include
> #include
> #include void testlog_snprintf(const char *fmt, ...)
> {
> va_list ap;
> int len;
> char bufMsg[50];
>
> memset(bufMsg,0x00,sizeof(bufMsg));
> len=0;
> va_start(ap, fmt);
> len=vsnprintf(bufMsg, sizeof(bufMsg), fmt, ap);
> //vsprintf(bufMsg, fmt, ap);
> int aa=0;
??? C or C++ ?

> va_end(ap);
> }
>

--
42Bastian
+
| http://www.sciopta.com
| Fastest direct message passing kernel.
| IEC61508 certified.
+
the len variable became a huge number, and into the bufMsg
there isn't nothing

--- In l..., 42Bastian wrote:
>
> smarini1963 schrieb:
> > I'm using crossworks for arm
> >
> > Below there is a little example, in which vsnprintf
> > report wrong result.
>
> Kind off ?
>
> > someone can help me to understand what I wrong?
> > ----- EXAMPLE--------
> > #include
> > #include
> > #include
> > #include
> >
> > void testlog_snprintf(const char *fmt, ...)
> > {
> > va_list ap;
> > int len;
> > char bufMsg[50];
> >
> > memset(bufMsg,0x00,sizeof(bufMsg));
> > len=0;
> > va_start(ap, fmt);
> > len=vsnprintf(bufMsg, sizeof(bufMsg), fmt, ap);
> > //vsprintf(bufMsg, fmt, ap);
> > int aa=0;
> ??? C or C++ ?
>
> > va_end(ap);
> > }
> > --
> 42Bastian
> +
> | http://www.sciopta.com
> | Fastest direct message passing kernel.
> | IEC61508 certified.
> +
>

may you copy what prints vsnprintf() and its return value?
smarini1963 ha scritto:
>
>
> I'm using crossworks for arm
>
> Below there is a little example, in which vsnprintf
> report wrong result.
>
> someone can help me to understand what I wrong?
> ----- EXAMPLE--------
> #include
> #include
> #include
> #include void testlog_snprintf(const char *fmt, ...)
> {
> va_list ap;
> int len;
> char bufMsg[50];
>
> memset(bufMsg,0x00,sizeof(bufMsg));
> len=0;
> va_start(ap, fmt);
> len=vsnprintf(bufMsg, sizeof(bufMsg), fmt, ap);
> //vsprintf(bufMsg, fmt, ap);
> int aa=0;
> va_end(ap);
> }
>
> int main (void)
> {
>
> testlog_snprintf("test %d",10);
>
> int aa=0;
> return aa;
> }
in the len the value is 0x000015e0
and into the buffer there is nothing, always 0x00

--- In l..., "M. Manca" wrote:
>
> may you copy what prints vsnprintf() and its return value?
> smarini1963 ha scritto:
> >
> >
> > I'm using crossworks for arm
> >
> > Below there is a little example, in which vsnprintf
> > report wrong result.
> >
> > someone can help me to understand what I wrong?
> > ----- EXAMPLE--------
> > #include
> > #include
> > #include
> > #include
> >
> > void testlog_snprintf(const char *fmt, ...)
> > {
> > va_list ap;
> > int len;
> > char bufMsg[50];
> >
> > memset(bufMsg,0x00,sizeof(bufMsg));
> > len=0;
> > va_start(ap, fmt);
> > len=vsnprintf(bufMsg, sizeof(bufMsg), fmt, ap);
> > //vsprintf(bufMsg, fmt, ap);
> > int aa=0;
> > va_end(ap);
> > }
> >
> > int main (void)
> > {
> >
> > testlog_snprintf("test %d",10);
> >
> > int aa=0;
> > return aa;
> > }
> >
>

> I'm using crossworks for arm
>
> Below there is a little example, in which vsnprintf
> report wrong result.
>
> someone can help me to understand what I wrong?
> ----- EXAMPLE--------
> #include
> #include
> #include
> #include void testlog_snprintf(const char *fmt, ...)
> {
> va_list ap;
> int len;
> char bufMsg[50];
>
> memset(bufMsg,0x00,sizeof(bufMsg));
> len=0;
> va_start(ap, fmt);
> len=vsnprintf(bufMsg, sizeof(bufMsg), fmt, ap);
> //vsprintf(bufMsg, fmt, ap);
> int aa=0;
> va_end(ap);
> }

Using:

void testlog_snprintf(const char *fmt, ...) {
va_list ap;
int len;
char bufMsg[50];

memset(bufMsg,0x00,sizeof(bufMsg));
len=0;
va_start(ap, fmt);
len=vsnprintf(bufMsg, sizeof(bufMsg), fmt, ap);
debug_printf("len = %d\n", len);
debug_printf("bufMsg = %s\n", bufMsg);
//vsprintf(bufMsg, fmt, ap);
int aa=0;
va_end(ap);
}

I get the output:

len = 7
bufMsg = test 10

-- Paul.

Tha

> -----Original Message-----
> From: l... [mailto:l...] On Behalf
Of
> smarini1963
> Sent: 07 January 2010 13:20
> To: l...
> Subject: [lpc2000] Re: problem with vsnprintf
>
> in the len the value is 0x000015e0
> and into the buffer there is nothing, always 0x00

That's not what I see.

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
CrossWorks V2 is out for LPC1700, LPC3100, LPC3200, SAM9, and more!

it's possible that I wrong something into the project configuration.

Can you send me your little project to ma email?
including the hzp file?

--- In l..., "Paul Curtis" wrote:
>
> > I'm using crossworks for arm
> >
> > Below there is a little example, in which vsnprintf
> > report wrong result.
> >
> > someone can help me to understand what I wrong?
> > ----- EXAMPLE--------
> > #include
> > #include
> > #include
> > #include
> >
> > void testlog_snprintf(const char *fmt, ...)
> > {
> > va_list ap;
> > int len;
> > char bufMsg[50];
> >
> > memset(bufMsg,0x00,sizeof(bufMsg));
> > len=0;
> > va_start(ap, fmt);
> > len=vsnprintf(bufMsg, sizeof(bufMsg), fmt, ap);
> > //vsprintf(bufMsg, fmt, ap);
> > int aa=0;
> > va_end(ap);
> > }
>
> Using:
>
> void testlog_snprintf(const char *fmt, ...) {
> va_list ap;
> int len;
> char bufMsg[50];
>
> memset(bufMsg,0x00,sizeof(bufMsg));
> len=0;
> va_start(ap, fmt);
> len=vsnprintf(bufMsg, sizeof(bufMsg), fmt, ap);
> debug_printf("len = %d\n", len);
> debug_printf("bufMsg = %s\n", bufMsg);
> //vsprintf(bufMsg, fmt, ap);
> int aa=0;
> va_end(ap);
> }
>
> I get the output:
>
> len = 7
> bufMsg = test 10
>
> -- Paul.
>

> Can you send me your little project to ma email?
> including the hzp file?

Done.

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
CrossWorks V2 is out for LPC1700, LPC3100, LPC3200, SAM9, and more!

thanks,
I discover what I wrong, the error wasn't into this routine but in another piece of code.

thanks,
anyway I learn to use the debug_printf

--- In l..., "Paul Curtis" wrote:
>
> > Can you send me your little project to ma email?
> > including the hzp file?
>
> Done.
>
> --
> Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
> CrossWorks V2 is out for LPC1700, LPC3100, LPC3200, SAM9, and more!
>


Memfault Beyond the Launch