nsgmls: resolve coverity warnings related to uninitialed members in C++ classes
[oweals/cde.git] / cde / programs / dtcreate / parser.c
index d8ff0b93bca439bf504d5987e2836704a914de76..13e855fea468695f5cbae60a64e101a79ed48075 100644 (file)
@@ -1,3 +1,25 @@
+/*
+ * CDE - Common Desktop Environment
+ *
+ * Copyright (c) 1993-2012, The Open Group. All rights reserved.
+ *
+ * These libraries and programs are free software; you can
+ * redistribute them and/or modify them under the terms of the GNU
+ * Lesser General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * These libraries and programs are distributed in the hope that
+ * they will be useful, but WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with these librararies and programs; if not, write
+ * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
+ * Floor, Boston, MA 02110-1301 USA
+ */
 /* $XConsortium: parser.c /main/8 1996/03/25 09:14:08 rswiston $ */
 /***************************************************************************/
 /*                                                                         */
@@ -52,7 +74,7 @@ char keywordDB[][30] = { "ACTION"         ,
                           "WINDOW_TYPE"   ,
                           "ARG_TYPE"      ,
                           "LABEL"         ,
-                          NULL            ,
+                          '\0'            ,
                      };
 
 /* Max Number of fields in Action Keyword Table */
@@ -76,7 +98,7 @@ char FiletypekeywordDB[][30] = { "DATA_ATTRIBUTES"       ,
                                   "MAP_ACTION"           ,
                                   "TYPE"                 ,
                                   "LABEL"                ,
-                                   NULL                  ,
+                                   '\0'                  ,
                      };
 
 /* Max Number of fields in Filetype Keyword Table */
@@ -118,8 +140,8 @@ char        linebuf[1024],**wordPairs,**execstr;
         rewind(fp);
         /* Initialize the ActionData structure passed */
         if(ActionDataptr)
-           memset((ActionData *)ActionDataptr,
-                       NULL,sizeof(ActionData));
+           memset(ActionDataptr,
+                       0,sizeof(ActionData));
         else {
 #ifdef DEBUG
            printf("ActionDataptr is NULL\n");
@@ -256,6 +278,7 @@ char        linebuf[1024],**wordPairs,**execstr;
             {
                 ActionDataptr->pszCmd = execstr[0];
                 ActionDataptr->pszPrompt = execstr[1];
+                free(execstr);
             }
             /* Got the ActionData,so, go get the FiletypeData */
             ActionDataptr->papFiletypes =
@@ -408,10 +431,12 @@ FiletypeData  **ppFiletypeData,**ppnewFiletypeData;
                                 return NULL;
                           }
                          /* Everything looks right so process the exec_string */
-                         if( !(execstr = ProcessExecString((char *)ppFiletypeData[nfiletypes]->pszPrintCmd)) )
-                             ppFiletypeData[nfiletypes]->pszPrintCmd=NULL;
-                         else
-                             ppFiletypeData[nfiletypes]->pszPrintCmd=execstr[0];
+                          if( !(execstr = ProcessExecString((char *)ppFiletypeData[nfiletypes]->pszPrintCmd)) )
+                              ppFiletypeData[nfiletypes]->pszPrintCmd=NULL;
+                          else {
+                              ppFiletypeData[nfiletypes]->pszPrintCmd=execstr[0];
+                              free(execstr);
+                         }
                           nfiletypes++;
                           /* Allocate a new filetypedata record */
                           if( (ppFiletypeData[nfiletypes] =
@@ -622,6 +647,7 @@ FiletypeData  **ppFiletypeData,**ppnewFiletypeData;
                 ppFiletypeData[nfiletypes] = 0;
             /* return number of filetypes */
             *nftypes = nfiletypes+1;
+            free(execstr);
             return ppFiletypeData;
 
         }
@@ -671,24 +697,25 @@ GetKeywordValuePairs(char *s, int *id, int table)
             ++s;
         if (!args[0])
         {
-            args[0] = (char *)malloc (s - wordStart + 1);
+            int szArgs0 = s - wordStart + 1;
+            args[0] = (char *)malloc (szArgs0);
             if (!args[0])
                 return NULL;
-            memset(args[0],0,sizeof(args[0]));
+            memset(args[0],0,szArgs0);
         }
         strncpy (args[0], wordStart, s - wordStart);
         args[0][s-wordStart] = '\0';
         if (!args[1])
         {
-            if(s)
-               args[1] = (char *)malloc (strlen(s)+1);
+           int szArgs1 = strlen(s) + 1;
+            args[1] = (char *)malloc (szArgs1);
             if (!args[1])
             {
                 if(args[0])
                 free(args[0]);
                 return NULL;
             }
-            memset(args[1],0,sizeof(args[1]));
+            memset(args[1],0,szArgs1);
         }
         /* Skip all leading spaces */
         while (*s && isspace (*s))
@@ -784,8 +811,8 @@ GetKeywordValuePairs(char *s, int *id, int table)
 **                                                              **
 ** Limitation : Supports only ONE prompt.                       **
 **                                                              **
-** Output     : returns 0 (No error).                           **
-**              returns >0 (Error).                             **
+** Output     : Pointer to 3-element result array from malloc,  **
+**              or NULL on error                                **
 **                                                              **
 ** Assumptions: a) Arg fields start with a '%' character.       **
 **              b) Prompt string start and end with '"' chara-  **
@@ -800,13 +827,15 @@ char **
 ProcessExecString(char *cmd)
 {
 
-char *s1, *s2,*s3,*s4,*argbuf,*exec_args[3];
+char *s1, *s2,*s3,*s4,*argbuf,**exec_args;
 int  done=FALSE, argfound=FALSE,promptfound=FALSE;
 
         if (!cmd) {
            return((char **)NULL);
         }
         s1=s2=s3=s4=argbuf=NULL;
+        exec_args = calloc(3, sizeof(char*));
+        if (!exec_args) return NULL;
         /* Allocate buffer for the cmd string */
         exec_args[0] = (char *)calloc(1,strlen(cmd)+1);
         exec_args[1] = exec_args[2] = NULL;
@@ -829,7 +858,7 @@ int  done=FALSE, argfound=FALSE,promptfound=FALSE;
                                              covers the complete string
                                              between %'s
                                             */
-                      if(argbuf) free(argbuf);
+                      if(argbuf) { free(argbuf); argbuf = NULL; }
                       if(s2)
                       {
                          argbuf = (char *)calloc(1,(s2-s1)+2);
@@ -852,10 +881,10 @@ int  done=FALSE, argfound=FALSE,promptfound=FALSE;
                            continue;
                       }
                 }
-                else if (s1 && *s1)
+                else if (*s1)
                 {
                      strcat(exec_args[0],s1);
-                     if(argbuf)   free(argbuf);
+                     if(argbuf)   { free(argbuf); argbuf = NULL; }
                      done = TRUE;
                      continue;
                 }
@@ -912,7 +941,7 @@ int  done=FALSE, argfound=FALSE,promptfound=FALSE;
                 argfound = FALSE;
                 s1=s2;
          }
-         if(argbuf) free(argbuf);
+         if(argbuf) { free(argbuf); argbuf = NULL; }
    return exec_args;
 }
 
@@ -989,8 +1018,10 @@ char    *s1,*tmp,*s2,buf[10],*cts;
                pFtD->fsFlags|=CA_FT_CNTLONG;
            else if ( !strcmp(buf,"short") )
                pFtD->fsFlags|=CA_FT_CNTSHORT;
-           else
+           else {
+               free(cts);
                return (-1);
+           }
         }
         while( *tmp && isspace(*tmp) )  tmp++;
         s2=tmp;