I have some segfault in my application and what I've seen happening is that "vsnprintf" always fails(it returns negative number, in my case "-1").
This is on aarch64 (arm64).
The segfault is because of some bad implementation in a third party library but I want to know what are the possible reasons of vsnprintf failing. Also, is there a way to see errno or the reason of vsnprintf fail with GDB in a core dump? I don't have the process running.
This is the relevant implementation:
int mg_printf(const char *fmt, ...) {
int len;
char mem[100];
va_list ap;
va_start(ap, fmt);
len = vsnprintf(mem, sizeof(mem), fmt, ap); // this fails all the time
va_end(ap);
return len;
}
// len is very sketchy
int len = 1602988490;
const char* pr = "[aaaa:bbbb:0000:0000:0000:0000:0000:0010]:12345";
mg_printf("Host: %.*s\r\n", len, pr);
So, as you can see, the "len" provided to vsnprintf in the va_list is very "sketchy". Can this be the reason of the fail? This "len" value is not intended but it's the result of some other calls.