Closed GoogleCodeExporter closed 9 years ago
Hi,
Further to my previous comment,
I have comment the "n = vsnprintf(buf, buflen, fmt, ap);" in mg_vsnprintf
function
and replace that line with "n = snprintf(buf, buflen, "%s", fmt);" and the code
seems
to be work.
Could any one update me the usage of vsnprintf in mongoose. Or shall I continue
with
this snprintf fix.
Awaiting for reply.
Thanks.
Original comment by asharud...@gmail.com
on 11 Mar 2010 at 3:29
You are mixing printf-family '%' argument replacement coding with URI-encoded
characters which are represented as %XX codes. Feeding the latter to any
printf-derivative as the /format/-string will cause (very) ill effects because
the
printf() will see those single '%' characters and assume those are introducing
yet
another argument to be copied into the format string.
Hence either your printf("%s", str) solution is correct as now your URL-encoded
character sequence isn't in the format string any longer but instead part of a
string
/argument/ which is copied into the result through the '%s' format element, or
you
could mix URI-encoded characters and printf() format strings by 'escaping' the
'%'
for those URI-encoded chars in there, e.g.
printf("%s/%%ce%%a4%%ce%%b5%%cf%%84%%ce%%b1%%ce%%bc%%ce%%ad%%ce%%bd%%ce%%b7",
"Test1");
This is not a mongoose issue but a generic issue with using printf()-family
functions. To see literal '%' in the output, it must be escaped in the format
string
as "%%".
Original comment by ger.hobbelt
on 25 Apr 2010 at 10:00
Thanks for your reply. I will check it once.
Original comment by asharud...@gmail.com
on 26 Apr 2010 at 5:10
Original comment by valenok
on 3 Sep 2010 at 4:00
I have missed to update to this thread. When I use mg_printf , it seems it
failed to send all bytes for some reasons. Actually I am trying to send some
encrypted/compressed content. I've tried it with even mongoose 3.4 (from the
github). Actually I have changed the code as below, and its working fine. This
is just for your reference. I have added the following function and use it.
int my_printf(struct mg_connection *, const char *fmt, int size, ...);
int my_printf(struct mg_connection *conn, const char *fmt, int size, ...)
{
int len, toRet;
va_list ap;
long length = size;
char* buf = NULL;
buf = (char*)malloc(length);
if (buf == NULL)
{
printf("my_printf failed. no of bytes.. %ld", length);
}
memset(buf, '\0', length);
memcpy(buf, fmt, length);
toRet = mg_write(conn, buf, length);
free(buf);
return toRet;
}
Thanks,
Original comment by asharud...@gmail.com
on 15 Dec 2012 at 10:03
Original issue reported on code.google.com by
asharud...@gmail.com
on 11 Mar 2010 at 12:11