dthelp: compiler warning and coverity warning fixes
authorPeter Howkins <flibble@users.sf.net>
Wed, 28 Mar 2018 23:21:44 +0000 (00:21 +0100)
committerPeter Howkins <flibble@users.sf.net>
Wed, 28 Mar 2018 23:21:44 +0000 (00:21 +0100)
14 files changed:
cde/programs/dthelp/dthelpgen/helpgen.c
cde/programs/dthelp/dthelpprint/Initialize.c
cde/programs/dthelp/dthelpprint/PrintManStrFile.c
cde/programs/dthelp/dthelpprint/PrintTopics.c
cde/programs/dthelp/dthelpprint/PrintUtil.c
cde/programs/dthelp/parser/canon1/helptag/help.c
cde/programs/dthelp/parser/canon1/helptag/special.h
cde/programs/dthelp/parser/pass1/helptag/help.c
cde/programs/dthelp/parser/pass1/helptag/xref.c
cde/programs/dthelp/parser/pass2/build/out.c
cde/programs/dthelp/parser/pass2/htag2/custom.c
cde/programs/dthelp/parser/pass2/util/conutil.c
cde/programs/dthelp/parser/pass2/util/fclndir.c
cde/programs/dthelp/parser/pass2/util/malloc.c

index 01b961f986f001ba6df5f982f28dd06c950533c5..69f2686437cd1559449410aa7a0a0867b5a306b3 100644 (file)
@@ -341,7 +341,7 @@ CreateVolumeLink (
         * put the abstract information about this
         * family in the header file
         */
-       fprintf (outTopic, GetMessage (3, 3, "<P before 1 first 1 left 1>\n"));
+       fprintf (outTopic, "%s", GetMessage (3, 3, "<P before 1 first 1 left 1>\n"));
 
        if (abstract != NULL)
          {
@@ -489,7 +489,7 @@ CreateFamily (
             */
            fprintf (out_topic, (GetMessage (3, 2, (char*)defaultTitle14)),
                                                                title);
-           fprintf (out_topic, (GetMessage (3, 3, "<P before 1 first 1 left 1>\n")));
+           fprintf (out_topic, "%s", (GetMessage (3, 3, "<P before 1 first 1 left 1>\n")));
            fprintf (out_topic, "%s\n", abstract);
            fprintf (out_topic, "</P>\n");
 
@@ -549,7 +549,7 @@ CreateFamily (
                        bitmap, familyName);
                  }
                else
-                   fprintf (out_header, GetMessage (3, 3, "<P before 1 first 1 left 1>\n"));
+                   fprintf (out_header, "%s", GetMessage (3, 3, "<P before 1 first 1 left 1>\n"));
                fprintf (out_header, "%s\n", abstract);
                fprintf (out_header, "</P></CHARACTERSET>\n");
 
@@ -579,6 +579,8 @@ CreateFamily (
          }
        XrmDestroyDatabase (db);
       }
+      
+    free (token);
     return result;
 }
 
index e2901d9f32e72aab7585588f4351c3123a48226a..acdde63c50fbea4d2e7be8f6a05cc1be3cac135b 100644 (file)
@@ -702,7 +702,7 @@ void Usage(void)
    };
     int i;
     for (i=0; usage[i]; i++)
-       printf(_DTGETMESSAGE(INSET,i,usage[i]));
+       printf("%s", _DTGETMESSAGE(INSET,i,usage[i]));
 }       /*$END$*/
 
 \f
@@ -726,7 +726,7 @@ void CalculatePageSize(
    char *          appclass)
 {       /*$CODE$*/
 
-   static struct unprintableMargins
+   struct unprintableMargins
    {
       int leftUnprintableMargin;
       int rightUnprintableMargin;
@@ -744,7 +744,7 @@ void CalculatePageSize(
 #define        MAXVALIDSIZE    4
 
    /* page size info */
-   static struct page 
+   struct page 
    {
       int width;
       int height;
@@ -1469,10 +1469,10 @@ void _DtHPrGetResources(
       if (debugHelpPrint)
       {
          if (*XtRefOffset(options,rsrc->resource_offset))
-             printf("options%s: %s\n", rsrc->resource_name, 
-                       *XtRefOffset(options,rsrc->resource_offset));
+             printf("options%s: %s\n",  (char *) rsrc->resource_name, 
+                        (char *) *XtRefOffset(options,rsrc->resource_offset));
          else
-             printf("options%s: <NULL>\n", rsrc->resource_name);
+             printf("options%s: <NULL>\n", (char *) rsrc->resource_name);
       }
    }
    /* and calculate the page sizes */
@@ -1530,12 +1530,12 @@ char * _DtHPrCreateTmpFile(
    newtmpfile=malloc((strlen(dirname) + FILENAMELEN + 2) * sizeof(char));
    if (NULL == newtmpfile)
    {
-      fprintf(stderr, _DTGETMESSAGE(INSET,45,
+      fprintf(stderr, "%s", _DTGETMESSAGE(INSET,45,
                      "Error: Unable to allocate memory for temporary file\n"));
    }
    else
    {
-      sprintf(newtmpfile,_DTGETMESSAGE(INSET,50,"%1$s/%2$s%3$d_%4$d%5$s"), 
+      sprintf(newtmpfile, _DTGETMESSAGE(INSET,50,"%1$s/%2$s%3$d_%4$d%5$s"), 
                dirname, prefix, getpid(), filecnt++, suffix );
    }
 
index 5929fa9694bffaf502054faa021c56c23b5e26ef..8c1fb1590f2117cee11fb50b39d4e45d0ef47cc7 100644 (file)
@@ -87,6 +87,7 @@ int _DtHPrPrintStringData(
    char cmdFormat[100];
    char prOffsetArg[30];
    int status;
+   int retval;
 
     if ( NULL == options->stringData )
     {
@@ -120,7 +121,9 @@ int _DtHPrPrintStringData(
              options->colsTextWidth, EMPTY_STR,                     /* fold */
              options->topicTitle, options->rowsHeight, EMPTY_STR); /* pr */
 
-   return _DtHPrGenFileOrPrint(options,"String",printCommand);
+   retval = _DtHPrGenFileOrPrint(options,"String",printCommand);
+   free(printCommand);
+   return retval;
 } /*$END$*/
 
 
@@ -144,6 +147,7 @@ int _DtHPrPrintDynamicStringData(
    char cmdFormat[100];
    char prOffsetArg[30];
    int status;
+   int retval;
 
     if ( NULL == options->stringData )
     {
@@ -177,8 +181,9 @@ int _DtHPrPrintDynamicStringData(
              options->colsTextWidth, EMPTY_STR,                     /* fold */
              options->topicTitle, options->rowsHeight, EMPTY_STR); /* pr */
 
-
-   return _DtHPrGenFileOrPrint(options,"String",printCommand);
+   retval = _DtHPrGenFileOrPrint(options,"String",printCommand);
+   free(printCommand);
+   return retval;
 } /*$END$*/
 
 \f
@@ -200,6 +205,7 @@ int _DtHPrPrintManPage(
    char *printCommand;
    char cmdFormat[100];
    int status;
+   int retval;
 
     if ( NULL == options->manPage )
     {
@@ -223,13 +229,15 @@ int _DtHPrPrintManPage(
    }
    
    /** generate the command **/
-    sprintf(cmdFormat, "%s %s",         /* man */
+    snprintf(cmdFormat, sizeof(cmdFormat), "%s %s",         /* man */
              options->manCommand, options->manArgs);
-    sprintf(printCommand, cmdFormat,
+    snprintf(printCommand, sizeof(MAX_COMMAND_LENGTH*sizeof(char)), cmdFormat,
              options->manPage);         /* man */
 
+  retval = _DtHPrGenFileOrPrint(options,options->manPage,printCommand);
+  free(printCommand);
 
-   return _DtHPrGenFileOrPrint(options,options->manPage,printCommand);
+   return retval;
 } /*$END$*/
    
 
@@ -253,6 +261,7 @@ int _DtHPrPrintHelpFile(
    char  cmdFormat[100];
    char prOffsetArg[30];
    int status;
+   int retval;
 
     if ( NULL == options->helpFile )
     {
@@ -284,6 +293,8 @@ int _DtHPrPrintHelpFile(
              options->colsTextWidth, options->helpFile,             /* fold */
              options->topicTitle, options->rowsHeight, EMPTY_STR); /* pr */
 
-   return _DtHPrGenFileOrPrint(options,options->helpFile,printCommand);
+   retval = _DtHPrGenFileOrPrint(options,options->helpFile,printCommand);
+   free(printCommand);
+   return retval;
 } /*$END$*/
    
index 5d200fb4bcb128bbc7a267bdaaf3220faf94ffee..a39cd4b239c08d800a209a1e27a7b76f78d3179b 100644 (file)
@@ -1012,6 +1012,8 @@ int DoStrColsWidth(
       wcstr[--wclen] = EOS;
    wcstombs(str,wcstr,len+1);
 
+   free(wcstr);
+
    return wclen;
 }       /*$END$*/
 
@@ -1091,6 +1093,9 @@ void GenHeadFootFormatArgs(
        /* put into state data */
        state->hffArgs.volumeDate = strdup(buf);
        state->hffArgs.volumeDateColsWidth = width;
+       
+       free(locDocId);
+       free(locDateStamp);
     }
 
     /* get today's date */
@@ -1749,6 +1754,8 @@ int ProcessSubTopics(
    /* if processing subtopics, reset subsection number */
    if(subSectNumIndex > 1) state->sectNums[subSectNumIndex] = 0;
    state->level = level;       /* state->level was modified by the FOR loop */
+
+   free(children);
    return ret;
 }
 
index b90b8bb7c863438bcaa4dbc352540598e2622776..98b748dd8880854b1b6db08518c86cc6b47f34ba 100644 (file)
@@ -204,7 +204,7 @@ int _DtHPrGenFileOrPrint(
    }
 
    /* put the shell print script in there */
-   sprintf(printCommand,"%s", options->shCommand,True);
+   sprintf(printCommand,"%s", options->shCommand);
 
    /* set all the options that are IPC to the print script */
    PutOpt(printCommand,OPT_LPDEST,options->printer,True);
@@ -221,7 +221,7 @@ int _DtHPrGenFileOrPrint(
 
    /* unlink(tmpfile);  ** NOTE: don't unlink; let the printCommand do it */
                         /* note the DTPRINTFILEREMOVE env var setting above */
-      
+   free(tmpfile);
    return(status);
 } /*$END$*/
 
index 2162595389fc629fabef04b21fb3b9dfc25c20e2..d1848be6a57719ffbd246a428d6a25290ba52dda 100644 (file)
@@ -24,6 +24,8 @@
 /*   Copyright (c) 1986, 1987, 1988, 1989 Hewlett-Packard Co. */
 /* Miscellaneous Procedures for HP Tag/TeX translator */
 
+#include <stdint.h>
+
 #include "userinc.h"
 #include "globdec.h"
 
@@ -307,7 +309,7 @@ while (TRUE)
     node[n] = current->next;
     if (! id[n])
        {
-       if ((int) current->data >= 0)
+       if ((intptr_t) current->data >= 0)
            m_err1("No glossary definition for %s", id);
        current = current->next;
        while (! current)
@@ -2194,13 +2196,13 @@ if (vgloss(gloss) == GLOSS)
        *(termp-1) = M_EOS;
        }
 
-    idn = (int) m_lookfortrie(base ? base : dterm, &gtree);
+    idn = (intptr_t) m_lookfortrie(base ? base : dterm, &gtree);
     if (idn < 0)
        idn = -idn;
     if (!idn)
        {
        idn = NextId();
-       m_ntrtrie(base ? base : dterm, &gtree, (void *) idn);
+       m_ntrtrie(base ? base : dterm, &gtree, (void *) (intptr_t) idn);
        }
     }
 
index b6c464c7d0871687a07db025777775ed516f5858..186800e09ba808a10562c19903de3f3d96597548 100644 (file)
  248, "fraction 1/2",                    UNSUPP, NULL, 0,
  251, "French double open quote",        UNSUPP, NULL, 0,
  252, "Solid square",                    UNSUPP, NULL, 0,
- 253, "French double close quote",       UNSUPP, NULL, NULL
+ 253, "French double close quote",       UNSUPP, NULL, 0
index fc36aab47036d1202b4b7e58f91b7060f9a5e2eb..474a6a0d4492dbc5036a501ad20afff857047536 100644 (file)
@@ -24,6 +24,8 @@
 /*   Copyright (c) 1986, 1987, 1988, 1989 Hewlett-Packard Co. */
 /* Miscellaneous Procedures for HP Tag/TeX translator */
 
+#include <stdint.h>
+
 #include "userinc.h"
 #include "globdec.h"
 
@@ -306,7 +308,7 @@ while (TRUE)
     node[n] = current->next;
     if (! id[n])
        {
-       if ((int) current->data >= 0)
+       if ((intptr_t) current->data >= 0)
            m_err1("No glossary definition for %s", id);
        current = current->next;
        while (! current)
@@ -1612,6 +1614,8 @@ else
     }
 
 _DtLcxCloseDb(&myDb);
+free(charset);
+free(lang);
 }
 
 
@@ -2192,13 +2196,13 @@ if (vgloss(gloss) == GLOSS)
        *(termp-1) = M_EOS;
        }
 
-    idn = (int) m_lookfortrie(base ? base : dterm, &gtree);
+    idn = (intptr_t) m_lookfortrie(base ? base : dterm, &gtree);
     if (idn < 0)
        idn = -idn;
     if (!idn)
        {
        idn = NextId();
-       m_ntrtrie(base ? base : dterm, &gtree, (void *) idn);
+       m_ntrtrie(base ? base : dterm, &gtree, (void *) (intptr_t) idn);
        }
     }
 
index 635fb9d0832b3d8720beab9ae742ff0c60ec2821..2d846a51ba7cd650f1f7079c34080f460dc53dfb 100644 (file)
@@ -155,7 +155,10 @@ strcpy(helpext, ".xrh");
 tex = fopen(helpbase, "w");
 fprintf(tex, "\\gobble\001%s\002%%\n", m_signon);
 fputs("% Generated Cross-Reference Macros (for a particular document)\n", tex);
-if (! xtree.data) return;
+if (! xtree.data) {
+       fclose(tex);
+       return;
+}
 
 n = 0;
 current = xtree.data;
index 98c35caf98e5fc8d0cf1ec6b34451d7425d55821..886b98ecc378b1277882b933b5d46d7b7c80e155 100644 (file)
@@ -544,6 +544,8 @@ void srefout(M_NOPAR)
       fputs(ndif, dtd) ;
       }
     SUBONE
+    
+    free(mapbysref);
     }
 
 /* Output one element block in a template */
index e29ea633ef9a5dff91c37f4f006b89f55cef4fda..2a64bb61ce2253096c228b6004581d2ba5d77c97 100644 (file)
@@ -231,7 +231,7 @@ SEARCH *searchp;
 char *mb_entcontent;
 
 mb_entcontent = MakeMByteString(entcontent);
-if (!*mb_entcontent) return NULL; /* null file name, don't open a directory */
+if (!mb_entcontent || !*mb_entcontent) return NULL; /* null file name, don't open a directory */
 
 open = fopen(mb_entcontent, "r");
 if (open)
index faaa908e39b3e070728d8d439d0a21989d1f27fd..a7cf22d9bc1cbf6c17c6a9ff682dd17285f1dcbe 100644 (file)
@@ -424,8 +424,12 @@ if (loading) newdlm = (char **) calloc(trysize, sizeof(M_WCHAR *));
 if (! newtransit || (loading && ! newdlm))
     {
     trysize = NUMDELIM + 1;
+    free(newtransit);
     newtransit = (int *) calloc(NUMCON * trysize, sizeof(int));
-    if (loading) newdlm = (char **) calloc(trysize, sizeof(M_WCHAR *));
+    if (loading) {
+      free(newdlm);
+      newdlm = (char **) calloc(trysize, sizeof(M_WCHAR *));
+    }
     }
 if (! newtransit || (loading && ! newdlm))
     {
index 92ea423f4020096cf75d47934cd7ab9af80bff83..9599a43a8aab6c83457e959afe38ce63f50476d9 100644 (file)
@@ -144,6 +144,7 @@ void copyfile(pfile1,pfile2)
        ret = system(pcmd);
        ret = snprintf(pcmd, slen, "touch %s",pfile2);
        ret = system(pcmd);
+       free(pcmd);
 }
 
 int nextchar(file, data)
index 7eff9d8e23bcf51dd94e38df72c34b156434b23e..60464cc757b44617ee16d0427ef5047b92f32094 100644 (file)
@@ -84,16 +84,13 @@ void *m_wctrace(
 #endif
   ) ;
 
-void m_free(block, msg)
-  void *block ;
-  char *msg ;
+void m_free(void *block, char *msg)
   {
     char buffer[32] ;
 
 #if defined(MSDOS)
     if (m_heapchk) m_heapdump() ;
 #endif
-    free(block) ;
     if (m_malftrace) {
 #if defined(hpux) || defined(_AIX) || defined(sun) || defined(USL) || defined(__uxp__)
       snprintf(buffer, 32, "%5x:%5x",
@@ -107,6 +104,7 @@ void m_free(block, msg)
       m_trace(msg) ;
       m_trace("\n") ;
       }      
+    free(block) ;
 #if defined(MSDOS)
     if (m_heapchk) m_heapdump() ;
 #endif