From 251627104a1cf5b61179d0501008de4ffb753e66 Mon Sep 17 00:00:00 2001 From: Joey Schulze Date: Sat, 25 Jul 2009 16:05:13 +0000 Subject: [PATCH] Be more explicit for malloc() calls --- dtaus.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/dtaus.c b/dtaus.c index 1390159..e8046ce 100644 --- a/dtaus.c +++ b/dtaus.c @@ -937,7 +937,7 @@ void dtaus2control (char *cdtaus, char *ccontrol) else if (!(fcontrol = fopen(ccontrol, "w"))) return; - if (!(buf = (char *)malloc (512))) + if ((buf = (char *)malloc (512)) == NULL) return; /* @@ -1176,7 +1176,7 @@ int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck, cha return 0; - if (!(buf = (char *)malloc (512))) + if ((buf = (char *)malloc (512)) == NULL) return 0; /* @@ -1192,7 +1192,7 @@ int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck, cha if ((recindex = rec_index(ident, REC_A)) != -1) { if (recA[recindex].type != IGN) - if ((valA[recindex] = (char *)malloc (strlen(line)+1))) + if ((valA[recindex] = (char *)malloc (strlen(line)+1)) != NULL) strcpy(valA[recindex], line); } else { if (! strcasecmp (ident, "euro")) @@ -1290,11 +1290,11 @@ int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck, cha } } if (textindex < MAX_TEXT) { - if ((cp = (char *)malloc (strlen (line) + 1))) { - strcpy (cp, line); - cp[strlen (line)] = '\0'; - text[textindex++] = cp; - } + if ((cp = (char *)malloc (strlen (line) + 1)) == NULL) + return 0; + strcpy (cp, line); + cp[strlen (line)] = '\0'; + text[textindex++] = cp; } } else { len = strlen(line); @@ -1303,24 +1303,23 @@ int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck, cha for (i=0; line[i]; i++) if (line[i] == ',') line[i] = '.'; if ((cp = strchr (line, '.')) == NULL) { - if (!(valC[recindex] = (char *)malloc (strlen(line)+4))) + if ((valC[recindex] = (char *)malloc (strlen(line)+4)) == NULL) return 0; sprintf (valC[recindex], "%s.00", line); } else if ( ((len = cp - line + 3)) < strlen (line)) { - if (!(valC[recindex] = (char *)malloc (len+1))) + if ((valC[recindex] = (char *)malloc (len+1)) == NULL) return 0; strncpy (valC[recindex], line, len); valC[recindex][len] = '\0'; } else { - if (!(valC[recindex] = (char *)malloc (strlen(line)+1))) + if ((valC[recindex] = (char *)malloc (strlen(line)+1)) == NULL) return 0; strcpy(valC[recindex], line); } } else { - if ((valC[recindex] = (char *)malloc (strlen(line)+1))) - strcpy(valC[recindex], line); - else + if ((valC[recindex] = (char *)malloc (strlen(line)+1)) == NULL) return 0; + strcpy(valC[recindex], line); } } } -- 2.20.1