From 94400f32e9016d2eaea2db583f6e213c36b1eb1d Mon Sep 17 00:00:00 2001 From: Daniel Gustafsson Date: Sat, 14 Apr 2018 22:42:04 +0200 Subject: all: Refactor malloc+memset to use calloc When a zeroed out allocation is required, use calloc() rather than malloc() followed by an explicit memset(). The result will be the same, but using calloc() everywhere increases consistency in the codebase and avoids the risk of subtle bugs when code is injected between malloc and memset by accident. Closes https://github.com/curl/curl/pull/2497 --- docs/examples/evhiperfifo.c | 1 - docs/examples/fopen.c | 4 +--- docs/examples/hiperfifo.c | 1 - 3 files changed, 1 insertion(+), 5 deletions(-) (limited to 'docs') diff --git a/docs/examples/evhiperfifo.c b/docs/examples/evhiperfifo.c index 257c127a7..c0c230b26 100644 --- a/docs/examples/evhiperfifo.c +++ b/docs/examples/evhiperfifo.c @@ -336,7 +336,6 @@ static void new_conn(char *url, GlobalInfo *g) CURLMcode rc; conn = calloc(1, sizeof(ConnInfo)); - memset(conn, 0, sizeof(ConnInfo)); conn->error[0]='\0'; conn->easy = curl_easy_init(); diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c index eb27c6ae9..f1706fbe6 100644 --- a/docs/examples/fopen.c +++ b/docs/examples/fopen.c @@ -237,12 +237,10 @@ URL_FILE *url_fopen(const char *url, const char *operation) URL_FILE *file; (void)operation; - file = malloc(sizeof(URL_FILE)); + file = calloc(1, sizeof(URL_FILE)); if(!file) return NULL; - memset(file, 0, sizeof(URL_FILE)); - file->handle.file = fopen(url, operation); if(file->handle.file) file->type = CFTYPE_FILE; /* marked as URL */ diff --git a/docs/examples/hiperfifo.c b/docs/examples/hiperfifo.c index 7794283c6..fec62b85f 100644 --- a/docs/examples/hiperfifo.c +++ b/docs/examples/hiperfifo.c @@ -339,7 +339,6 @@ static void new_conn(char *url, GlobalInfo *g) CURLMcode rc; conn = calloc(1, sizeof(ConnInfo)); - memset(conn, 0, sizeof(ConnInfo)); conn->error[0]='\0'; conn->easy = curl_easy_init(); -- cgit v1.2.3