1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-15 04:32:24 +00:00

dthelp: Further coverity fixes

This commit is contained in:
Peter Howkins 2018-04-30 04:11:44 +01:00
parent c936a8c065
commit 48b97a4c41
15 changed files with 76 additions and 55 deletions

View file

@ -305,7 +305,6 @@ CreateVolumeLink (
char *title = NULL; char *title = NULL;
char *charSet = (char *) DefCharSet; char *charSet = (char *) DefCharSet;
char *abstract = NULL; char *abstract = NULL;
char *filename = NULL;
char *pathName = NULL; char *pathName = NULL;
VolumeHandle volume = NULL; VolumeHandle volume = NULL;
@ -359,8 +358,6 @@ CreateVolumeLink (
if (title) if (title)
free ((void *) title); free ((void *) title);
if (filename)
free ((void *) filename);
return result; return result;
} }

View file

@ -218,10 +218,11 @@ int _DtHPrPrintManPage(
} }
/* Alloc max shell command line len */ /* Alloc max shell command line len */
printCommand = malloc(MAX_COMMAND_LENGTH*sizeof(char)); printCommand = malloc(MAX_COMMAND_LENGTH);
if (printCommand == NULL) if (printCommand == NULL)
{ {
fprintf(stderr, _DTGETMESSAGE(PMSET,5, fprintf(stderr, _DTGETMESSAGE(PMSET,5,
"%s: Error: memory allocation failed\n"), "%s: Error: memory allocation failed\n"),
options->programName ); options->programName );
@ -231,7 +232,7 @@ int _DtHPrPrintManPage(
/** generate the command **/ /** generate the command **/
snprintf(cmdFormat, sizeof(cmdFormat), "%s %s", /* man */ snprintf(cmdFormat, sizeof(cmdFormat), "%s %s", /* man */
options->manCommand, options->manArgs); options->manCommand, options->manArgs);
snprintf(printCommand, sizeof(MAX_COMMAND_LENGTH*sizeof(char)), cmdFormat, snprintf(printCommand, MAX_COMMAND_LENGTH, cmdFormat,
options->manPage); /* man */ options->manPage); /* man */
retval = _DtHPrGenFileOrPrint(options,options->manPage,printCommand); retval = _DtHPrGenFileOrPrint(options,options->manPage,printCommand);

View file

@ -2273,13 +2273,11 @@ int ProcessTopics(
/* if processing subtopics, start processing at the top */ /* if processing subtopics, start processing at the top */
if ( processSubTopics ) if ( processSubTopics )
{ {
char * name = NULL;
int offset; int offset;
/* get the top topic of the volume */ /* get the top topic of the volume */
ret = _DtHelpCeGetTopTopicId(state->volHandle, &state->currentLocId); ret = _DtHelpCeGetTopTopicId(state->volHandle, &state->currentLocId);
if (ret != True) state->currentLocId = strdup("_HOMETOPIC"); if (ret != True) state->currentLocId = strdup("_HOMETOPIC");
if(name) free(name);
} }
else else
{ /* otherwise, process only where needed */ { /* otherwise, process only where needed */
@ -2413,7 +2411,7 @@ int DoHelpTopicsProcessing(
char * buf; char * buf;
char * start; char * start;
char * next; char * next;
char * pgbrkFile; char * pgbrkFile = NULL;
char * partFiles[NUMPARTS]; char * partFiles[NUMPARTS];
Boolean validFile = False; Boolean validFile = False;
@ -2514,7 +2512,10 @@ cleanup:
unlink(partFiles[i]); unlink(partFiles[i]);
free(partFiles[i]); free(partFiles[i]);
} }
if(pgbrkFile) {
unlink(pgbrkFile); unlink(pgbrkFile);
}
/* NOTE: should free Toc here if interested in no leaks */ /* NOTE: should free Toc here if interested in no leaks */

View file

@ -166,13 +166,16 @@ void CloseHelpCB (
pTemp = pCacheListHead; pTemp = pCacheListHead;
/* Search our Cache List for the closed help dialog */ /* Search our Cache List for the closed help dialog */
while ((pTemp->helpDialog != helpDialog) && (pTemp != NULL)) while ((pTemp != NULL) && (pTemp->helpDialog != helpDialog))
pTemp = pTemp->pNext; pTemp = pTemp->pNext;
if (pTemp == NULL) if (pTemp == NULL) {
/* ERROR */ /* ERROR */
printf("We did not find our help dialog widget in the cache list??? /n"); printf("We did not find our help dialog widget in the cache list??? /n");
/* TODO what error handling here? */
return;
}
/* Un Map and Clean up the help widget */ /* Un Map and Clean up the help widget */
XtUnmanageChild(helpDialog); XtUnmanageChild(helpDialog);

View file

@ -75,7 +75,7 @@ int main(argc, argv)
fprintf(stderr, "**** Specify interface file ****\n") ; fprintf(stderr, "**** Specify interface file ****\n") ;
exit(TRUE) ; exit(TRUE) ;
} }
strncpy(iffile, argv[1], IFLEN) ; snprintf(iffile, sizeof(iffile), "%s", argv[1]) ;
initialize() ; initialize() ;
while (TRUE) { while (TRUE) {
m_token = scan() ; m_token = scan() ;

View file

@ -126,7 +126,7 @@ if ( *(m_argv[0]) == '/' )
else else
{ {
/* not fully specified, check each component of path for ourself */ /* not fully specified, check each component of path for ourself */
strcpy(patbuf, getenv("PATH")); snprintf(patbuf, sizeof(patbuf), "%s", getenv("PATH"));
path = patbuf; path = patbuf;
cp = path; cp = path;
@ -538,8 +538,10 @@ M_WCHAR *parent, *gentity, *gposition, *ghyperlink, *glinktype, *gdescription;
{ {
unsigned char etype, wheredef; unsigned char etype, wheredef;
char *mb_content, *ssi, id[32]; char *mb_content, *ssi, id[32];
static M_WCHAR empty = M_EOS; static M_WCHAR empty[1];
char *leftright; char *leftright;
empty[0] = M_EOS;
/* handle graphic specific code */ /* handle graphic specific code */
/* initialize some stuff first: /* initialize some stuff first:
@ -627,7 +629,7 @@ if (gentity)
gentity); gentity);
} }
} }
if (!f_content) f_content = ∅ if (!f_content) f_content = empty;
mb_content = MakeMByteString(f_content); mb_content = MakeMByteString(f_content);
sprintf(id, "%s%d", sdlReservedName, NextId()); sprintf(id, "%s%d", sdlReservedName, NextId());
@ -718,7 +720,7 @@ int count, metaCount;
char *item_id; char *item_id;
char label_id[SDLNAMESIZ+10]; char label_id[SDLNAMESIZ+10];
int listtype; int listtype;
char *type; char *type = NULL;
char *loose; char *loose;
char *first; char *first;
LOGICAL isBullet, isLoose, isFirst; LOGICAL isBullet, isLoose, isFirst;
@ -824,9 +826,10 @@ if (listtype == ORDER)
switch (lastlist->lastlist->order) switch (lastlist->lastlist->order)
{ {
case UROMAN: case UROMAN:
strcpy(orderString, ROMAN100[count / 100]); snprintf(orderString, sizeof(orderString), "%s%s%s",
strcat(orderString, ROMAN10[(count / 10) % 10]); ROMAN100[count / 100],
strcat(orderString, ROMAN0[count % 10]); ROMAN10[(count / 10) % 10],
ROMAN0[count % 10]);
type = romanString; type = romanString;
break; break;
case UALPHA: case UALPHA:
@ -848,9 +851,10 @@ if (listtype == ORDER)
type = arabicString; type = arabicString;
break; break;
case LROMAN: case LROMAN:
strcpy(orderString, roman100[count / 100]); snprintf(orderString, sizeof(orderString), "%s%s%s",
strcat(orderString, roman10[(count / 10) % 10]); roman100[count / 100],
strcat(orderString, roman0[count % 10]); roman10[(count / 10) % 10],
roman0[count % 10]);
type = romanString; type = romanString;
break; break;
case LALPHA: case LALPHA:
@ -868,7 +872,7 @@ if (listtype == ORDER)
"%s%s-%s\">\n<P>%s%c", "%s%s-%s\">\n<P>%s%c",
first, first,
loose, loose,
type, type ? type : "",
orderString, orderString,
lastlist->lastlist->punct == DOTPUNCT ? '.' : ')' ); lastlist->lastlist->punct == DOTPUNCT ? '.' : ')' );
if (id) if (id)
@ -1508,17 +1512,19 @@ _DtXlateDb myDb = NULL;
char myPlatform[_DtPLATFORM_MAX_LEN+1]; char myPlatform[_DtPLATFORM_MAX_LEN+1];
char myLocale[256]; /* arbitrarily large */ char myLocale[256]; /* arbitrarily large */
char *locale; char *locale;
char *lang; char *lang = NULL;
char *charset; char *charset = NULL;
int execVer; int execVer;
int compVer; int compVer;
int isStd; int isStd;
strcpy(myLocale, pLang);
if (*pCharset) if (*pCharset)
{ {
strcat(myLocale, "."); snprintf(myLocale, sizeof(myLocale), "%s.%s", pLang, pCharset);
strcat(myLocale, pCharset); }
else
{
snprintf(myLocale, sizeof(myLocale), "%s", pLang);
} }
if ((_DtLcxOpenAllDbs(&myDb) != 0) || if ((_DtLcxOpenAllDbs(&myDb) != 0) ||
@ -1601,7 +1607,6 @@ else
if (*lang) if (*lang)
{ {
strcpy(pLang, lang); strcpy(pLang, lang);
mb_free(&lang);
} }
else else
strcpy(pLang, cString); strcpy(pLang, cString);
@ -1609,13 +1614,16 @@ else
if (*charset) if (*charset)
{ {
strcpy(pCharset, charset); strcpy(pCharset, charset);
mb_free(&charset);
free(charset);
} }
else else
strcpy(pCharset, isoString); strcpy(pCharset, isoString);
} }
mb_free(&lang);
mb_free(&charset);
free(charset);
_DtLcxCloseDb(&myDb); _DtLcxCloseDb(&myDb);
} }
@ -1773,9 +1781,9 @@ if (!charset)
if (dotPtr) if (dotPtr)
*dotPtr = 0; *dotPtr = 0;
strcpy(stdLang, locale); snprintf(stdLang, sizeof(stdLang), "%s", locale);
if (charset) if (charset)
strcpy(stdCharset, charset); snprintf(stdCharset, sizeof(stdCharset), "%s", charset);
SetStdLocale(stdLang, stdCharset); SetStdLocale(stdLang, stdCharset);
if (*stdCharset) if (*stdCharset)
@ -2049,10 +2057,12 @@ if (file)
sprintf(snb_id, "%s%d", sdlReservedName, NextId()); sprintf(snb_id, "%s%d", sdlReservedName, NextId());
{ {
static M_WCHAR empty = M_EOS; static M_WCHAR empty[1];
char *mb_content; char *mb_content;
empty[0] = M_EOS;
if (!f_content) f_content = &empty;
if (!f_content) f_content = empty;
mb_content = MakeMByteString(f_content); mb_content = MakeMByteString(f_content);
AddToSNB(snb_id, mb_content); AddToSNB(snb_id, mb_content);
@ -2763,8 +2773,8 @@ if (*icon)
fputs("CLASS=\"ICON\" SSI=\"NCW-ICON\">", outfile); fputs("CLASS=\"ICON\" SSI=\"NCW-ICON\">", outfile);
fputs("</REFITEM>\n</SNREF></HEAD>\n", outfile); fputs("</REFITEM>\n</SNREF></HEAD>\n", outfile);
AddToSNB(id, icon); AddToSNB(id, icon);
m_free(icon, "icon name");
} }
m_free(icon, "icon name");
} }
@ -2838,8 +2848,7 @@ while (thispath)
else else
try = mb_realloc(try, tryleng); try = mb_realloc(try, tryleng);
} }
strcpy(try, thispath->directory); sprintf(try, "%s%s", thispath->directory, mb_inputname);
strcpy(try + pathleng, mb_inputname);
tossfile = open(try, O_RDONLY); tossfile = open(try, O_RDONLY);
if (tossfile >= 0) break; if (tossfile >= 0) break;
thispath = thispath->next; thispath = thispath->next;

View file

@ -516,15 +516,15 @@ static char ident6[]="@(#) (c) Copyright 1993, 1994 Unix System Labs, Inc., a su
if (termp - term > 1 && *(termp-1) == ' ') { if (termp - term > 1 && *(termp-1) == ' ') {
*(termp-1) = M_EOS; *(termp-1) = M_EOS;
} }
if (!(lastTermId = (int) m_lookfortrie(term, &gtree))) if (!(lastTermId = (int)(intptr_t) m_lookfortrie(term, &gtree)))
{ {
lastTermId = NextId(); lastTermId = NextId();
m_ntrtrie(term, &gtree, (void *) -lastTermId); m_ntrtrie(term, &gtree, (void *)(intptr_t) -lastTermId);
} }
else else
if (lastTermId > 0) if (lastTermId > 0)
{ {
if (!m_resettrie(&gtree, term, (void *) -lastTermId)) if (!m_resettrie(&gtree, term, (void *)(intptr_t) -lastTermId))
{ {
m_error("Internal error. Can't reset glossary trie") ; m_error("Internal error. Can't reset glossary trie") ;
m_exit(TRUE) ; m_exit(TRUE) ;
@ -685,7 +685,7 @@ static char ident6[]="@(#) (c) Copyright 1993, 1994 Unix System Labs, Inc., a su
m_error("Program error: exceeded chapstring") ; m_error("Program error: exceeded chapstring") ;
m_exit(TRUE) ; m_exit(TRUE) ;
} }
sprintf(chapstring, sizeof(chapstring), "%s", string) ; snprintf(chapstring, sizeof(chapstring), "%s", string) ;
fputs("\nGlossary\n", stderr) ; fputs("\nGlossary\n", stderr) ;
glossary = TRUE ; glossary = TRUE ;
fprintf(outfile, "<HEAD SSI=\"CHAPHEAD\">%s</HEAD>\n", string); fprintf(outfile, "<HEAD SSI=\"CHAPHEAD\">%s</HEAD>\n", string);
@ -778,9 +778,10 @@ static char ident6[]="@(#) (c) Copyright 1993, 1994 Unix System Labs, Inc., a su
{ {
char *mb_content, snb_id[32]; char *mb_content, snb_id[32];
char buffer[BIGBUF]; char buffer[BIGBUF];
static M_WCHAR empty = M_EOS; static M_WCHAR empty[1];
empty[0] = M_EOS;
if (!f_content) f_content = &empty; if (!f_content) f_content = empty;
mb_content = MakeMByteString(f_content); mb_content = MakeMByteString(f_content);
sprintf(snb_id, "%s%d", sdlReservedName, NextId()); sprintf(snb_id, "%s%d", sdlReservedName, NextId());

View file

@ -198,7 +198,7 @@ if (bufflen == 1)
exLineNum++; exLineNum++;
if (special[index]) if (special[index])
{ {
strcpy(exbuff, special[index]); snprintf(exbuff, sizeof(exbuff), "%s", special[index]);
bufflen = strlen(exbuff); bufflen = strlen(exbuff);
} }
} }
@ -230,7 +230,7 @@ if (bufflen == 1)
index = (unsigned char) imbuff[0]; index = (unsigned char) imbuff[0];
if (special[index]) if (special[index])
{ {
strcpy(imbuff, special[index]); snprintf(imbuff, sizeof(imbuff), "%s", special[index]);
bufflen = strlen(imbuff); bufflen = strlen(imbuff);
} }
mb_strcode(imbuff, outfile); mb_strcode(imbuff, outfile);

View file

@ -72,8 +72,7 @@ void entout(fname)
int nameindex ; int nameindex ;
LOGICAL start ; LOGICAL start ;
strncpy(efilename, fname, ENTFILENAME) ; snprintf(efilename, sizeof(efilename), "%s.h", fname) ;
strncpy(&efilename[strlen(efilename)], ".h", 2) ;
m_openchk(&entfile, efilename, "w") ; m_openchk(&entfile, efilename, "w") ;
fprintf(entfile, "#include \"entdef.h\"\n") ; fprintf(entfile, "#include \"entdef.h\"\n") ;

View file

@ -210,7 +210,11 @@ SEARCH *searchp;
char *mb_entcontent; char *mb_entcontent;
mb_entcontent = MakeMByteString(entcontent); mb_entcontent = MakeMByteString(entcontent);
if (!*mb_entcontent) return NULL; /* null file name, don't open a directory */ if (!*mb_entcontent) /* null file name, don't open a directory */
{
m_free(mb_entcontent, "multi-byte string");
return NULL;
}
open = fopen(mb_entcontent, "r"); open = fopen(mb_entcontent, "r");
if (open) if (open)
@ -301,7 +305,9 @@ void m_signmsg(p)
if (q = strstr(p, VERSION)) { if (q = strstr(p, VERSION)) {
pCopy = strdup(p); pCopy = strdup(p);
q = strstr(pCopy, VERSION); q = strstr(pCopy, VERSION);
if(q) {
*q = M_EOS; *q = M_EOS;
}
m_errline(pCopy); m_errline(pCopy);
free(pCopy); free(pCopy);
return; return;

View file

@ -870,9 +870,10 @@ static char ident6[]="@(#) (c) Copyright 1993, 1994 Unix System Labs, Inc., a su
{ {
char *mb_content, snb_id[32]; char *mb_content, snb_id[32];
char buffer[BIGBUF]; char buffer[BIGBUF];
static M_WCHAR empty = M_EOS; static M_WCHAR empty[1];
empty[0] = M_EOS;
if (!f_content) f_content = &empty; if (!f_content) f_content = empty;
mb_content = MakeMByteString(f_content); mb_content = MakeMByteString(f_content);
sprintf(snb_id, "%s%d", sdlReservedName, NextId()); sprintf(snb_id, "%s%d", sdlReservedName, NextId());

View file

@ -153,6 +153,9 @@ FILE *tex;
strcpy(helpext, ".xrh"); strcpy(helpext, ".xrh");
tex = fopen(helpbase, "w"); tex = fopen(helpbase, "w");
if (! tex) {
return;
}
fprintf(tex, "\\gobble\001%s\002%%\n", m_signon); fprintf(tex, "\\gobble\001%s\002%%\n", m_signon);
fputs("% Generated Cross-Reference Macros (for a particular document)\n", tex); fputs("% Generated Cross-Reference Macros (for a particular document)\n", tex);
if (! xtree.data) { if (! xtree.data) {

View file

@ -93,7 +93,6 @@ void m_free(block, msg)
#if defined(MSDOS) #if defined(MSDOS)
if (m_heapchk) m_heapdump() ; if (m_heapchk) m_heapdump() ;
#endif #endif
free(block) ;
if (m_malftrace) { if (m_malftrace) {
#if defined(hpux) || defined(_AIX) || defined(sun) || defined(USL) || defined(__uxp__) #if defined(hpux) || defined(_AIX) || defined(sun) || defined(USL) || defined(__uxp__)
snprintf(buffer, 32, "%5x:%5x", snprintf(buffer, 32, "%5x:%5x",
@ -107,6 +106,7 @@ void m_free(block, msg)
m_trace(msg) ; m_trace(msg) ;
m_trace("\n") ; m_trace("\n") ;
} }
free(block) ;
#if defined(MSDOS) #if defined(MSDOS)
if (m_heapchk) m_heapdump() ; if (m_heapchk) m_heapdump() ;
#endif #endif

View file

@ -483,7 +483,7 @@ char *partype(n)
void srefout(M_NOPAR) void srefout(M_NOPAR)
{ {
LOGICAL first = TRUE ; LOGICAL first = TRUE ;
int *mapbysref ; int *mapbysref = NULL;
SREFSTRUCT *srefp ; SREFSTRUCT *srefp ;
SREFDATA *data ; SREFDATA *data ;
int count = 0 ; int count = 0 ;

View file

@ -1563,7 +1563,7 @@ static void MarkUsedStyle(level, class, ssi)
#endif #endif
{ {
ElementPtr pThis; ElementPtr pThis;
M_WCHAR *rlevel, *rclass, *rssi; M_WCHAR *rlevel = NULL, *rclass = NULL, *rssi = NULL;
LOGICAL *pBeenUsed; LOGICAL *pBeenUsed;
pThis = pTossChain; pThis = pTossChain;