Clean up generateStatsJson error handling a bit
This commit is contained in:
parent
ab7aa856bc
commit
490b5ce36f
16
net_io.c
16
net_io.c
|
|
@ -1820,8 +1820,13 @@ static char * appendStatsJson(char *p,
|
||||||
}
|
}
|
||||||
|
|
||||||
char *generateStatsJson(const char *url_path, int *len) {
|
char *generateStatsJson(const char *url_path, int *len) {
|
||||||
struct stats add;
|
const size_t bufsize = 4096;
|
||||||
char *buf = (char *) malloc(4096), *p = buf, *end = buf + 4096;
|
char *buf = malloc(bufsize), *p = buf, *end = buf + bufsize;
|
||||||
|
if (!buf) {
|
||||||
|
// allocation failed, give up
|
||||||
|
*len = 0;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
MODES_NOTUSED(url_path);
|
MODES_NOTUSED(url_path);
|
||||||
|
|
||||||
|
|
@ -1842,9 +1847,12 @@ char *generateStatsJson(const char *url_path, int *len) {
|
||||||
p = appendStatsJson(p, end, &add, "total");
|
p = appendStatsJson(p, end, &add, "total");
|
||||||
p = safe_snprintf(p, end, "\n}\n");
|
p = safe_snprintf(p, end, "\n}\n");
|
||||||
|
|
||||||
assert(p < end);
|
if (p <= end) {
|
||||||
|
*len = p-buf;
|
||||||
|
} else {
|
||||||
|
*len = 0; // ran out of buffer space, give up
|
||||||
|
}
|
||||||
|
|
||||||
*len = p-buf;
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue