replace sprintf by snprintf (silence warning by macOS compiler)

This commit is contained in:
F. Duncanh
2023-04-15 04:43:00 -04:00
parent 4a86c90c18
commit 67e9c0eca1
8 changed files with 29 additions and 17 deletions

View File

@@ -276,14 +276,19 @@ http_request_get_header_string(http_request_t *request, char **header_str)
assert(str);
*header_str = str;
char *p = str;
int n = sizeof(str);
for (int i = 0; i < request->headers_size; i++) {
sprintf(p,"%s", request->headers[i]);
p += strlen(request->headers[i]);
int hlen = strlen(request->headers[i]);
snprintf(p, n, "%s", request->headers[i]);
n -= hlen;
p += hlen;
if (i%2 == 0) {
sprintf(p, ": ");
p +=2;
snprintf(p, n, ": ");
n -= 2;
p += 2;
} else {
sprintf(p, "\n");
snprintf(p, n, "\n");
n--;
p++;
}
}