From e12e009eb5fe891d99bcfb952527bd1391a691e9 Mon Sep 17 00:00:00 2001 From: Peter Howkins Date: Thu, 29 Mar 2018 00:21:44 +0100 Subject: [PATCH] dthelp: compiler warning and coverity warning fixes --- cde/programs/dthelp/dthelpgen/helpgen.c | 8 +++--- cde/programs/dthelp/dthelpprint/Initialize.c | 16 ++++++------ .../dthelp/dthelpprint/PrintManStrFile.c | 25 +++++++++++++------ cde/programs/dthelp/dthelpprint/PrintTopics.c | 7 ++++++ cde/programs/dthelp/dthelpprint/PrintUtil.c | 4 +-- .../dthelp/parser/canon1/helptag/help.c | 8 +++--- .../dthelp/parser/canon1/helptag/special.h | 2 +- .../dthelp/parser/pass1/helptag/help.c | 10 +++++--- .../dthelp/parser/pass1/helptag/xref.c | 5 +++- cde/programs/dthelp/parser/pass2/build/out.c | 2 ++ .../dthelp/parser/pass2/htag2/custom.c | 2 +- .../dthelp/parser/pass2/util/conutil.c | 6 ++++- .../dthelp/parser/pass2/util/fclndir.c | 1 + .../dthelp/parser/pass2/util/malloc.c | 6 ++--- 14 files changed, 68 insertions(+), 34 deletions(-) diff --git a/cde/programs/dthelp/dthelpgen/helpgen.c b/cde/programs/dthelp/dthelpgen/helpgen.c index 01b961f9..69f26864 100644 --- a/cde/programs/dthelp/dthelpgen/helpgen.c +++ b/cde/programs/dthelp/dthelpgen/helpgen.c @@ -341,7 +341,7 @@ CreateVolumeLink ( * put the abstract information about this * family in the header file */ - fprintf (outTopic, GetMessage (3, 3, "

\n")); + fprintf (outTopic, "%s", GetMessage (3, 3, "

\n")); if (abstract != NULL) { @@ -489,7 +489,7 @@ CreateFamily ( */ fprintf (out_topic, (GetMessage (3, 2, (char*)defaultTitle14)), title); - fprintf (out_topic, (GetMessage (3, 3, "

\n"))); + fprintf (out_topic, "%s", (GetMessage (3, 3, "

\n"))); fprintf (out_topic, "%s\n", abstract); fprintf (out_topic, "

\n"); @@ -549,7 +549,7 @@ CreateFamily ( bitmap, familyName); } else - fprintf (out_header, GetMessage (3, 3, "

\n")); + fprintf (out_header, "%s", GetMessage (3, 3, "

\n")); fprintf (out_header, "%s\n", abstract); fprintf (out_header, "

\n"); @@ -579,6 +579,8 @@ CreateFamily ( } XrmDestroyDatabase (db); } + + free (token); return result; } diff --git a/cde/programs/dthelp/dthelpprint/Initialize.c b/cde/programs/dthelp/dthelpprint/Initialize.c index e2901d9f..acdde63c 100644 --- a/cde/programs/dthelp/dthelpprint/Initialize.c +++ b/cde/programs/dthelp/dthelpprint/Initialize.c @@ -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$*/ @@ -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: \n", rsrc->resource_name); + printf("options%s: \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 ); } diff --git a/cde/programs/dthelp/dthelpprint/PrintManStrFile.c b/cde/programs/dthelp/dthelpprint/PrintManStrFile.c index 5929fa96..8c1fb159 100644 --- a/cde/programs/dthelp/dthelpprint/PrintManStrFile.c +++ b/cde/programs/dthelp/dthelpprint/PrintManStrFile.c @@ -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$*/ @@ -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$*/ diff --git a/cde/programs/dthelp/dthelpprint/PrintTopics.c b/cde/programs/dthelp/dthelpprint/PrintTopics.c index 5d200fb4..a39cd4b2 100644 --- a/cde/programs/dthelp/dthelpprint/PrintTopics.c +++ b/cde/programs/dthelp/dthelpprint/PrintTopics.c @@ -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; } diff --git a/cde/programs/dthelp/dthelpprint/PrintUtil.c b/cde/programs/dthelp/dthelpprint/PrintUtil.c index b90b8bb7..98b748dd 100644 --- a/cde/programs/dthelp/dthelpprint/PrintUtil.c +++ b/cde/programs/dthelp/dthelpprint/PrintUtil.c @@ -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$*/ diff --git a/cde/programs/dthelp/parser/canon1/helptag/help.c b/cde/programs/dthelp/parser/canon1/helptag/help.c index 21625953..d1848be6 100644 --- a/cde/programs/dthelp/parser/canon1/helptag/help.c +++ b/cde/programs/dthelp/parser/canon1/helptag/help.c @@ -24,6 +24,8 @@ /* Copyright (c) 1986, 1987, 1988, 1989 Hewlett-Packard Co. */ /* Miscellaneous Procedures for HP Tag/TeX translator */ +#include + #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, >ree); + idn = (intptr_t) m_lookfortrie(base ? base : dterm, >ree); if (idn < 0) idn = -idn; if (!idn) { idn = NextId(); - m_ntrtrie(base ? base : dterm, >ree, (void *) idn); + m_ntrtrie(base ? base : dterm, >ree, (void *) (intptr_t) idn); } } diff --git a/cde/programs/dthelp/parser/canon1/helptag/special.h b/cde/programs/dthelp/parser/canon1/helptag/special.h index b6c464c7..186800e0 100644 --- a/cde/programs/dthelp/parser/canon1/helptag/special.h +++ b/cde/programs/dthelp/parser/canon1/helptag/special.h @@ -241,4 +241,4 @@ 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 diff --git a/cde/programs/dthelp/parser/pass1/helptag/help.c b/cde/programs/dthelp/parser/pass1/helptag/help.c index fc36aab4..474a6a0d 100644 --- a/cde/programs/dthelp/parser/pass1/helptag/help.c +++ b/cde/programs/dthelp/parser/pass1/helptag/help.c @@ -24,6 +24,8 @@ /* Copyright (c) 1986, 1987, 1988, 1989 Hewlett-Packard Co. */ /* Miscellaneous Procedures for HP Tag/TeX translator */ +#include + #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, >ree); + idn = (intptr_t) m_lookfortrie(base ? base : dterm, >ree); if (idn < 0) idn = -idn; if (!idn) { idn = NextId(); - m_ntrtrie(base ? base : dterm, >ree, (void *) idn); + m_ntrtrie(base ? base : dterm, >ree, (void *) (intptr_t) idn); } } diff --git a/cde/programs/dthelp/parser/pass1/helptag/xref.c b/cde/programs/dthelp/parser/pass1/helptag/xref.c index 635fb9d0..2d846a51 100644 --- a/cde/programs/dthelp/parser/pass1/helptag/xref.c +++ b/cde/programs/dthelp/parser/pass1/helptag/xref.c @@ -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; diff --git a/cde/programs/dthelp/parser/pass2/build/out.c b/cde/programs/dthelp/parser/pass2/build/out.c index 98c35caf..886b98ec 100644 --- a/cde/programs/dthelp/parser/pass2/build/out.c +++ b/cde/programs/dthelp/parser/pass2/build/out.c @@ -544,6 +544,8 @@ void srefout(M_NOPAR) fputs(ndif, dtd) ; } SUBONE + + free(mapbysref); } /* Output one element block in a template */ diff --git a/cde/programs/dthelp/parser/pass2/htag2/custom.c b/cde/programs/dthelp/parser/pass2/htag2/custom.c index e29ea633..2a64bb61 100644 --- a/cde/programs/dthelp/parser/pass2/htag2/custom.c +++ b/cde/programs/dthelp/parser/pass2/htag2/custom.c @@ -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) diff --git a/cde/programs/dthelp/parser/pass2/util/conutil.c b/cde/programs/dthelp/parser/pass2/util/conutil.c index faaa908e..a7cf22d9 100644 --- a/cde/programs/dthelp/parser/pass2/util/conutil.c +++ b/cde/programs/dthelp/parser/pass2/util/conutil.c @@ -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)) { diff --git a/cde/programs/dthelp/parser/pass2/util/fclndir.c b/cde/programs/dthelp/parser/pass2/util/fclndir.c index 92ea423f..9599a43a 100644 --- a/cde/programs/dthelp/parser/pass2/util/fclndir.c +++ b/cde/programs/dthelp/parser/pass2/util/fclndir.c @@ -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) diff --git a/cde/programs/dthelp/parser/pass2/util/malloc.c b/cde/programs/dthelp/parser/pass2/util/malloc.c index 7eff9d8e..60464cc7 100644 --- a/cde/programs/dthelp/parser/pass2/util/malloc.c +++ b/cde/programs/dthelp/parser/pass2/util/malloc.c @@ -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 -- 2.25.1