commit dae2db6af7b7dc33a9b2cdb1c88e0b17fef181b7
parent 97aa1785bdba9e221f54433c146f72931342ce2c
Author: Francesco Saccone <francesco@francescosaccone.com>
Date: Mon, 31 Mar 2025 19:49:08 +0200
fix: do not remove the length of template patterns from size
The result when removing the template patterns was the cutting of
the last two bytes from the buffer. As said in the comment, I
don't care about 10ish bytes more than needed.
Signed-off-by: Francesco Saccone <francesco@francescosaccone.com>
Diffstat:
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/http.c b/http.c
@@ -63,17 +63,17 @@ compose_http_response(struct http_response response) {
/*
* This is actually a bit inelegant: it adds the length of 'template'
- * with the length of each component of http_response; it then removes
- * the number of characters occupied by template patterns of the form
- * '%x', that is, 2 times the number of template patterns used.
+ * with the length of each component of http_response; it will result
+ * in something bigger than the actual size of the response due to
+ * the template patterns in %, but that is just a few bytes and nobody
+ * really minds it.
*/
size = strlen(template)
+ get_length_of_integer(status_code)
+ strlen(status_message)
+ strlen(content_type)
+ get_length_of_integer(strlen(body))
- + strlen(body)
- - 2 * 5;
+ + strlen(body);
buffer = malloc(size);