]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
fix errors found by coverity
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 8 Jun 2011 15:32:54 +0000 (17:32 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 8 Jun 2011 15:34:54 +0000 (17:34 +0200)
dialogboxes.c
listbox.c
whiptail.c
windows.c

index c3478f9a9c1036152f81835de36129b9e954de0f..4850e5566b00e64edf7430dacb64ba662eafe4b8 100644 (file)
@@ -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;
 }
index 6b6bb4290fdae0441da77a7f86a5294697869222..6177c07fddf1c5ced3008b6e490da176329808ab 100644 (file)
--- 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);
index a0da6e1631cdd61803d3eb925483c2c9b0461885..f7169e0c0356129556e0acfb6e7aa85eac1395c3 100644 (file)
@@ -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;
 }
index 45035fd6c889d1296693253c934b8dab9a171875..239fad4d68b880570e2e97a48b432efd1b164c22 100644 (file)
--- 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);