From 149121fe597e9d3ee818d6d1d0facf9175d6674d Mon Sep 17 00:00:00 2001 From: Kamil Dudka Date: Tue, 15 Nov 2011 19:24:00 +0100 Subject: [PATCH 1/2] units - fix defects found by Coverity --- units.c | 18 +++++++++++------- 1 files changed, 11 insertions(+), 7 deletions(-) diff --git a/units.c b/units.c index cdda76a..c4230c9 100644 --- a/units.c +++ b/units.c @@ -383,7 +383,7 @@ readunits(char *file, FILE *errfile, struct prefixlist *pfxptr; struct unitlist *uptr; FILE *unitfile; - char *line, *lineptr, *unitdef, *unitname, *permfile; + char *line = 0, *lineptr, *unitdef, *unitname, *permfile; int len, linenum, linebufsize, goterr; unsigned hashval, pval; int locunitcount, locprefixcount, locfunccount; @@ -399,12 +399,13 @@ readunits(char *file, FILE *errfile, growbuffer(&line,&linebufsize); - permfile = dupstr(file); /* This is a permanent copy to - reference in the database. - It is never freed. */ unitfile = fopen(file, "rt"); if (!unitfile) return E_FILE; + + permfile = dupstr(file); /* This is a permanent copy to + reference in the database. + It is never freed. */ while (!feof(unitfile)) { if (!fgetslong(&line, &linebufsize, unitfile, &linenum)) break; @@ -471,8 +472,10 @@ readunits(char *file, FILE *errfile, } readerr = readunits(includefile, errfile, unitcount, prefixcount, funccount, depth+1); - if (readerr == E_MEMORY) + if (readerr == E_MEMORY) { + fclose(unitfile); return readerr; + } if (readerr == E_FILE) { if (errfile) fprintf(errfile, "%s: unable to open included file '%s' at line %d of file '%s\n", progname, includefile, linenum, file); @@ -1381,7 +1384,8 @@ subunitroot(int n,char *in[], char *out[]) char **ptr,**current; int count; - for(current = in;*current && *current==NULLUNIT;current++); + for(current = in;*current==NULLUNIT;current++) + if (!*current) return E_NOTROOT; count = 0; for(ptr=in;*ptr;ptr++){ if (*ptr==NULLUNIT) continue; @@ -2618,7 +2622,7 @@ Typing 'search text' will show units whose names contain 'text'.\n\n", int main(int argc, char **argv) { - struct unittype have, want; + static struct unittype have, want; char *havestr=0, *wantstr=0; struct func *funcval; int havestrsize=0; /* Only used if READLINE is undefined */ -- 1.7.1 From 30ede89a0147189cd815afc58b1d82545b881bcd Mon Sep 17 00:00:00 2001 From: Kamil Dudka Date: Wed, 16 Nov 2011 13:37:09 +0100 Subject: [PATCH 2/2] units - use an annotation to suppress a false positive of Coverity --- units.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/units.c b/units.c index c4230c9..28555a4 100644 --- a/units.c +++ b/units.c @@ -403,6 +403,7 @@ readunits(char *file, FILE *errfile, if (!unitfile) return E_FILE; + /* coverity[alloc_fn] */ permfile = dupstr(file); /* This is a permanent copy to reference in the database. It is never freed. */ -- 1.7.1