From 8cdb3ba9256bf61453c25ee728349cd18dabe236 Mon Sep 17 00:00:00 2001 From: Soikk Date: Wed, 10 Dec 2025 19:55:12 +0100 Subject: Removed naked allocations for strings --- src/net/net.c | 3 +-- src/rewrites/rewrites.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/net/net.c b/src/net/net.c index ce1c815..39b25e3 100755 --- a/src/net/net.c +++ b/src/net/net.c @@ -397,8 +397,7 @@ static uint64_t http_len(struct http_message *hm){ }*/ static str http_header_to_str(struct http_message *hm){ - str s = {0}; - s.ptr = calloc(http_len(hm) + 1, sizeof(char)); + str s = dnstr(http_len(hm)); copy_strs(s, hm->method, sstr(" "), hm->url, sstr(" "), hm->req_ver, sstr("\r\n")); for(int i = 0; i < hm->hlen; i++){ copy_strs(s, hm->headers[i].name, sstr(": "), hm->headers[i].value, sstr("\r\n")); diff --git a/src/rewrites/rewrites.c b/src/rewrites/rewrites.c index a8c53ce..0968779 100644 --- a/src/rewrites/rewrites.c +++ b/src/rewrites/rewrites.c @@ -62,12 +62,11 @@ int check_pattern(str text, str pattern, str tokens[9]){ } str fill_blueprint(str bp, str tokens[9]){ - str r = {0}; int rlen = 0; for(int i = 0; i < bp.len; i++, rlen++){ if(bp.ptr[i] == '$') rlen += tokens[bp.ptr[++i]-'1'].len-1; } - r.ptr = calloc(rlen+1, sizeof(char)); + str r = dnstr(rlen); if(r.ptr == NULL){ return r; } -- cgit v1.2.3