xujianxin / mongoose

Automatically exported from code.google.com/p/mongoose
MIT License
0 stars 0 forks source link

mg_printf with empty string incorrectly causes "vsnprintf() error" #386

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. The line that says: send_http_error(conn, 304, "Not Modified", "%s", ""); 

What is the expected output? 
An empty response without errors in the debug output.

What do you see instead?
a cry about vsnprintf() error in the debug output.

What version of the product are you using? On what operating system?
Mongoose 3.1
On Windows 7 64 bit

Please provide any additional information below.

vsnprintf is called with a format string of "%s" and an empty string "".
This causes vsnprintf to return 0, as it has 0 bytes written.
A return value of 0 is not an error of vsnprintf. 
In case of an error vsnprintf returns -1.

Therefore the line that checks the return value is incorrect.
This can be fixed in the function mg_printf:
Line 1494:   if (len <= 0) {
should be:   if (len < 0) {

Original issue reported on code.google.com by jeroen.w...@gmail.com on 19 Sep 2012 at 8:25

GoogleCodeExporter commented 8 years ago
This is already fixed in the HEAD, thanks.
https://github.com/valenok/mongoose/blob/master/mongoose.c#L1521

Original comment by valenok on 19 Sep 2012 at 9:55