From: Miroslav Lichvar Date: Wed, 8 Jun 2011 15:32:54 +0000 (+0200) Subject: fix errors found by coverity X-Git-Tag: r0-52-13~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3341bdc52b116d40cd20f21f7f7d8b7cc7977fd5;p=thirdparty%2Fnewt.git fix errors found by coverity --- diff --git a/dialogboxes.c b/dialogboxes.c index c3478f9..4850e55 100644 --- a/dialogboxes.c +++ b/dialogboxes.c @@ -186,6 +186,8 @@ int gauge(const char * text, int height, int width, poptContext optCon, int fd, } } while (!feof(f)); + newtFormDestroy(form); + return DLG_OKAY; } @@ -217,6 +219,8 @@ int inputBox(const char * text, int height, int width, poptContext optCon, *result = val; + newtFormDestroy(form); + return rc; } @@ -344,7 +348,8 @@ int listBox(const char * text, int height, int width, poptContext optCon, int len, j; len = mystrncpyw(buf, itemInfo[i].tag, MAXBUF, &w); for (j = 0; j < tagWidth - w; j++) { - if (len >= MAXBUF) break; + if (len + 1 >= MAXBUF) + break; buf[len++] = ' '; } buf[len] = '\0'; @@ -375,6 +380,9 @@ int listBox(const char * text, int height, int width, poptContext optCon, i = (long) newtListboxGetCurrent(listBox); *result = itemInfo[i].tag; + newtFormDestroy(form); + free(itemInfo); + return rc; } @@ -398,7 +406,7 @@ int checkList(const char * text, int height, int width, poptContext optCon, const char * tag; newtComponent comp; } * cbInfo = malloc(allocedBoxes * sizeof(*cbInfo)); - char * cbStates = malloc(allocedBoxes * sizeof(cbStates)); + char * cbStates = malloc(allocedBoxes * sizeof(*cbStates)); if ( (cbInfo == NULL) || (cbStates == NULL)) return DLG_ERROR; if (!(arg = poptGetArg(optCon))) return DLG_ERROR; @@ -507,6 +515,8 @@ int checkList(const char * text, int height, int width, poptContext optCon, (*selections)[numSelected] = NULL; } + newtFormDestroy(form); + return rc; } @@ -557,8 +567,8 @@ int messageBox(const char * text, int height, int width, int type, int flags) { newtDrawForm(form); newtRefresh(); } - + newtFormDestroy(form); return rc; } diff --git a/listbox.c b/listbox.c index 6b6bb42..6177c07 100644 --- a/listbox.c +++ b/listbox.c @@ -315,7 +315,8 @@ void newtListboxSetData(newtComponent co, int num, void * data) { for(i = 0, item = li->boxItems; item != NULL && i < num; i++, item = item->next); - item->data = data; + if (item) + item->data = data; } int newtListboxAppendEntry(newtComponent co, const char * text, @@ -669,7 +670,7 @@ static struct eventResult listboxEvent(newtComponent co, struct event ev) { li->currItem > li->startShowItem) li->startShowItem = li->currItem > li->numItems - li->curHeight ? - li->startShowItem = li->numItems - li->curHeight : + li->numItems - li->curHeight : li->currItem; if(li->sb) newtScrollbarSet(li->sb, li->currItem + 1, li->numItems); diff --git a/whiptail.c b/whiptail.c index a0da6e1..f7169e0 100644 --- a/whiptail.c +++ b/whiptail.c @@ -306,8 +306,10 @@ readTextFile(const char * filename) exit(DLG_ERROR); } - if ( (buf = malloc(s.st_size + 1)) == 0 ) + if ( (buf = malloc(s.st_size + 1)) == 0 ) { fprintf(stderr, _("%s: too large to display.\n"), filename); + exit(DLG_ERROR); + } if ( read(fd, buf, s.st_size) != s.st_size ) { perror(filename); @@ -483,7 +485,11 @@ int main(int argc, const char ** argv) { if (!(nextArg = poptGetArg(optCon))) usage(WAS_ERROR); text = strdup(nextArg); - if (mode == MODE_TEXTBOX ) text = readTextFile(text); + if (mode == MODE_TEXTBOX) { + char *t = text; + text = readTextFile(t); + free(t); + } if (!(nextArg = poptGetArg(optCon))) usage(WAS_ERROR); height = strtoul(nextArg, &end, 10); @@ -495,8 +501,14 @@ int main(int argc, const char ** argv) { if (mode == MODE_GAUGE) { fd = dup(0); - close(0); - if (open("/dev/tty", O_RDWR) != 0) perror("open /dev/tty"); + if (fd < 0 || close(0) < 0) { + perror("dup/close stdin"); + exit(DLG_ERROR); + } + if (open("/dev/tty", O_RDWR) != 0) { + perror("open /dev/tty"); + exit(DLG_ERROR); + } } newtInit(); @@ -602,5 +614,8 @@ int main(int argc, const char ** argv) { newtPopWindow(); newtFinished(); + free(text); + poptFreeContext(optCon); + return ( rc == DLG_ESCAPE ) ? -1 : rc; } diff --git a/windows.c b/windows.c index 45035fd..239fad4 100644 --- a/windows.c +++ b/windows.c @@ -167,7 +167,7 @@ int newtWinMenu(char * title, char * text, int suggestedWidth, int flexDown, ++totalButtons; va_end(args); - buttons = (newtComponent *)alloca(sizeof(newtComponent*)*(totalButtons)); + buttons = (newtComponent *)alloca(sizeof(newtComponent)*(totalButtons)); va_start(args, button1); for (buttonName = button1; buttonName; buttonName = va_arg(args, char *)) buttons[numButtons++] = newtButton(-1, -1, buttonName); @@ -226,7 +226,7 @@ int newtWinEntries(char * title, char * text, int suggestedWidth, int flexDown, ++totalButtons; va_end(args); - buttons = (newtComponent *)alloca(sizeof(newtComponent*)*(totalButtons)); + buttons = (newtComponent *)alloca(sizeof(newtComponent)*(totalButtons)); va_start(args, button1); for (buttonName = button1; buttonName; buttonName = va_arg(args, char *)) buttons[numButtons++] = newtButton(-1, -1, buttonName);