From 61415b606977b8bcff797263abc946ab21a31b9a Mon Sep 17 00:00:00 2001 From: Mid Favila Date: Wed, 7 Dec 2022 11:55:31 -0400 Subject: [PATCH] Remove redundant malloc+memset calls in favor of calloc. --- src/gopher.c | 9 ++++----- src/http.c | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/gopher.c b/src/gopher.c index 4c3cd46..c39b264 100644 --- a/src/gopher.c +++ b/src/gopher.c @@ -12,11 +12,10 @@ int reqgen_gopher(const char *path, char **nbuf) buflen = (strlen(REQ_GOPH) + strlen(path) + 1); - if( !(*nbuf = malloc(buflen))) - { - return(ERRMEM); - } - memset(*nbuf, 0, buflen); + if( !(*nbuf = calloc(buflen, sizeof(char)))) + { + return(ERRMEM); + } sprintf(*nbuf, REQ_GOPH, path); diff --git a/src/http.c b/src/http.c index aa20975..831a22a 100644 --- a/src/http.c +++ b/src/http.c @@ -12,11 +12,10 @@ int reqgen_http(const char *path, const char *fqdn, char **nbuf) buflen = (strlen(REQ_HTTP) + strlen(path) + strlen(fqdn) + 1); - if( !(*nbuf = malloc(buflen))) - { - return(ERRMEM); - } - memset(*nbuf, 0, buflen); + if( !(*nbuf = calloc(buflen, sizeof(char)))) + { + return(ERRMEM); + } sprintf(*nbuf, REQ_HTTP, path, fqdn);