cesanta / mongoose

Embedded Web Server

Home Page:https://mongoose.ws

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mg_queue_prinf() sets wrong Content-Length / queue size.

T-a-n-d-E-m opened this issue · comments

The following snippet sets the queue length to 2 (the length of the format string) not the expected 13 (the length of the final string generated).

// Create the queue and init it ...
char buffer[1024];
mg_queue queue;
mg_queue_init(&queue, buffer, 1024);

// ... later on
const char* str = "Hello, World!";
mg_queue_printf(&queue, "%s", str);

I'm using release 7.12.

There is an issue template for a reason: to save yours and our time. Please honor it.

$ cat pp.c
#include "mongoose.h"

int main(void) {
  char buffer[1024];
  struct mg_queue queue;
  mg_queue_init(&queue, buffer, 1024);
  const char* str = "Hello, World!";
  MG_INFO(("%u",mg_queue_printf(&queue, "%s", str)));
}
$ gcc -o pp pp.c mongoose.c
$ ./pp
150f3a10 2 pp.c:8:main                  13
$

Please follow the guidelines in the documentation, examples and tutorials available.