From a3c2b432b50c49305c60e42f5b9f1759ef3c1368 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Wed, 14 Jul 2010 16:08:55 +0000 Subject: Squash mimetype may be used uninitialised warning. svn path=/trunk/netsurf/; revision=10638 --- render/directory.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'render/directory.c') diff --git a/render/directory.c b/render/directory.c index 04f5991c7..6ff149713 100644 --- a/render/directory.c +++ b/render/directory.c @@ -143,7 +143,8 @@ bool directory_convert(struct content *c) { bool compare; char *up; struct stat filestat; - char *filepath, *mimetype; + char *filepath, *mimetype = NULL; + int filepath_size; char moddate[100]; char modtime[100]; bool extendedinfo, evenrow = false; @@ -235,21 +236,25 @@ bool directory_convert(struct content *c) { /* Skip . and .. entries */ continue; - extendedinfo = false; - - filepath = malloc(strlen(path) + strlen(entry->d_name) + 2); + filepath_size = strlen(path) + strlen(entry->d_name) + 2; + filepath = malloc(filepath_size); if (filepath != NULL) { strcpy(filepath, path); - if (path_add_part(filepath, - (strlen(path) + - strlen(entry->d_name) + 2), - entry->d_name)) { - if (stat(filepath, &filestat) == 0) { - mimetype = fetch_mimetype(filepath); - extendedinfo = true; - } + if (path_add_part(filepath, filepath_size, + entry->d_name) == false) { + msg_data.error = messages_get("MiscErr"); + content_broadcast(c, CONTENT_MSG_ERROR, + msg_data); + return false; } - free(filepath); + if (stat(filepath, &filestat) == 0) + extendedinfo = true; + else + extendedinfo = false; + } else { + msg_data.error = messages_get("MiscErr"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + return false; } /* Start row and print item name */ @@ -288,6 +293,7 @@ bool directory_convert(struct content *c) { moddate, modtime); } else { /* File: Print type, size, and date/time */ + mimetype = fetch_mimetype(filepath); snprintf(buffer, sizeof(buffer), "%s " "%d" @@ -319,8 +325,11 @@ bool directory_convert(struct content *c) { else evenrow = false; - if (mimetype) + if (mimetype != NULL) { free(mimetype); + mimetype = NULL; + } + free(filepath); } closedir(parent); -- cgit v1.2.3