From 55c59be795e848b93448923852d450d61be63f6d Mon Sep 17 00:00:00 2001 From: Peter Howkins Date: Wed, 28 Mar 2018 01:29:28 +0100 Subject: [PATCH] dtcudcfonted: Resolve compiler and coverity warnings --- cde/programs/dtudcfonted/code.c | 26 +++++----- cde/programs/dtudcfonted/dtaddcpf/addcpf.c | 3 +- .../dtudcfonted/dtcpftogpf/cpftogpf.c | 2 +- cde/programs/dtudcfonted/dtcpgpf/cpgpf.c | 3 +- .../dtudcfonted/dtgpftobdf/gpftobdf.c | 29 ++++++------ .../dtudcfonted/dtgpftocpf/gpftocpf.c | 15 +++--- cde/programs/dtudcfonted/libfal/_fallcDB.c | 1 + .../dtudcfonted/libfal/_fallcGeneric.c | 29 +++++++----- cde/programs/dtudcfonted/libfal/_fallcWrap.c | 7 +-- .../dtudcfonted/libfal/_falomGeneric.c | 34 +++++++------- cde/programs/dtudcfonted/libfal/_faludcInf.c | 18 +++---- cde/programs/dtudcfonted/libfal/falfont.c | 47 +++++++------------ cde/programs/dtudcfonted/libfal/readpcf.c | 7 +-- cde/programs/dtudcfonted/libfuty/oakfuty.c | 11 ++++- cde/programs/dtudcfonted/mtfgui.c | 6 +-- cde/programs/dtudcfonted/util.c | 4 +- 16 files changed, 127 insertions(+), 115 deletions(-) diff --git a/cde/programs/dtudcfonted/code.c b/cde/programs/dtudcfonted/code.c index 10c42ca0..6969634f 100644 --- a/cde/programs/dtudcfonted/code.c +++ b/cde/programs/dtudcfonted/code.c @@ -104,7 +104,7 @@ Widget w; int low_code; { int hi_code; - char *f; + char *f = NULL; XImage image; GC gc = XDefaultGC(display, 0); @@ -124,8 +124,9 @@ int low_code; if (open_font) { f = (char *)FalReadFont(fid, hi_code | low_code, font_w, font_h); - if(f == (char *)FAL_ERROR) + if(f == NULL || f == (char *)FAL_ERROR) { return; + } if( EXISTS_FLAG == 0 ) { memcpy(ptn, f, len); image.data = (char *)ptn; @@ -147,7 +148,7 @@ static void SetPixmap(start_code) { int hi_code, low_code; - char *f; + char *f = NULL; XImage image; GC gc = XDefaultGC(display, 0); @@ -168,8 +169,9 @@ SetPixmap(start_code) if (open_font) { for (low_code=0; low_code < NUM; low_code++) { f = (char *)FalReadFont(fid, hi_code | low_code, font_w, font_h); - if(f == (char *)FAL_ERROR) + if(f == NULL || f == (char *)FAL_ERROR) { return; + } if( EXISTS_FLAG == 0 ) { memcpy(ptn, f, len); image.data = (char *)ptn; @@ -316,7 +318,7 @@ Widget w; XmString item[128]; XmString xcs; int item_count, start_code, add_c; - char add[3]; + char add[9]; n = 0; XtSetArg(args[n], XmNmwmFunctions, MWM_FUNC_ALL | MWM_FUNC_CLOSE | @@ -342,9 +344,9 @@ Widget w; scroll = XmCreateScrolledList(base2, "scroll", args, n); XtManageChild(scroll); XtAddCallback(scroll, XmNbrowseSelectionCallback, - (XtCallbackProc)Code1Call, (XtPointer)start_code); + (XtCallbackProc)Code1Call, (XtPointer) (intptr_t) start_code); XtAddCallback(scroll, XmNdefaultActionCallback, - (XtCallbackProc)Code1Call, (XtPointer)start_code); + (XtCallbackProc)Code1Call, (XtPointer) (intptr_t) start_code); XmListSelectPos(scroll, 1, False); base3 = XtVaCreateManagedWidget("base3", xmRowColumnWidgetClass, base2, @@ -377,7 +379,7 @@ Widget w; add_c = 0; for (i=0; i < NUM; i++) { if ((i % 16) == 0) { - sprintf(add, "%2.1X", add_c++); + snprintf(add, sizeof(add), "%2.1X", add_c++); XtVaCreateManagedWidget(add, xmLabelWidgetClass, base3, NULL); } toggle[i] = XtVaCreateWidget("toggle", @@ -387,13 +389,13 @@ Widget w; XmNlabelType, XmPIXMAP, XmNlabelPixmap, no_pix, NULL); XtAddCallback(toggle[i], XmNactivateCallback, - (XtCallbackProc)Code2Call, (XtPointer)i); + (XtCallbackProc)Code2Call, (XtPointer) (intptr_t) i); XtAddCallback(toggle[i], XmNarmCallback, - (XtCallbackProc)DrawCode, (XtPointer)i); + (XtCallbackProc)DrawCode, (XtPointer) (intptr_t) i); XtAddCallback(toggle[i], XmNdisarmCallback, - (XtCallbackProc)DrawCode, (XtPointer)i); + (XtCallbackProc)DrawCode, (XtPointer) (intptr_t) i); XtAddEventHandler(toggle[i], ExposureMask, False, - (XtEventHandler)DrawCode, (XtPointer)i); + (XtEventHandler)DrawCode, (XtPointer) (intptr_t) i); } XtManageChildren(toggle, NUM); diff --git a/cde/programs/dtudcfonted/dtaddcpf/addcpf.c b/cde/programs/dtudcfonted/dtaddcpf/addcpf.c index b9b63205..5dfb5240 100644 --- a/cde/programs/dtudcfonted/dtaddcpf/addcpf.c +++ b/cde/programs/dtudcfonted/dtaddcpf/addcpf.c @@ -220,7 +220,7 @@ char *argv[]; exit( 1 ); } - if ( ReadSnf.in_file == '\0' && xlfdname == '\0' ) { + if ( ReadSnf.in_file == NULL && xlfdname == NULL ) { if ( code_area & SYSTM ) { USAGE1("%s : The GPF output file name cannot be omitted.\n", argv[0] ); } else { /* string of charcter size */ @@ -526,6 +526,7 @@ int init_all; close( pfd[1] ); close( 1 ); if( dup( ofd ) < 0 ) { + close( ofd ); return DUP_ERROR; } close( ofd ); diff --git a/cde/programs/dtudcfonted/dtcpftogpf/cpftogpf.c b/cde/programs/dtudcfonted/dtcpftogpf/cpftogpf.c index 4516c80c..41ca900c 100644 --- a/cde/programs/dtudcfonted/dtcpftogpf/cpftogpf.c +++ b/cde/programs/dtudcfonted/dtcpftogpf/cpftogpf.c @@ -204,7 +204,7 @@ char *argv[]; exit( 1 ); } - if ( Head.snf_file == NULL && xlfdname == '\0' ) { + if ( Head.snf_file == NULL && xlfdname == NULL ) { if ( code_area & SYSTM ) { USAGE1("%s : The SNF output file name cannot be omitted.\n", argv[0] ); } else { diff --git a/cde/programs/dtudcfonted/dtcpgpf/cpgpf.c b/cde/programs/dtudcfonted/dtcpgpf/cpgpf.c index 77a3742a..ddfc5bcb 100644 --- a/cde/programs/dtudcfonted/dtcpgpf/cpgpf.c +++ b/cde/programs/dtudcfonted/dtcpgpf/cpgpf.c @@ -549,7 +549,7 @@ char *style ; { - if ( gpfinf->in_file == '\0' && xlfdname == '\0' ) { + if ( gpfinf->in_file == NULL && xlfdname == NULL ) { if ( code_area & SYSTM ) { USAGE1("%s : The GPF output file name cannot be omitted.\n", com ); } else { /* string of charcter size */ @@ -703,6 +703,7 @@ int type ; close( pfd[1] ); close( 1 ); if( dup( out_fd ) < 0 ) { + close( out_fd ); return DUP_ERROR; } close( out_fd ); diff --git a/cde/programs/dtudcfonted/dtgpftobdf/gpftobdf.c b/cde/programs/dtudcfonted/dtgpftobdf/gpftobdf.c index 02eb2823..26cecbad 100644 --- a/cde/programs/dtudcfonted/dtgpftobdf/gpftobdf.c +++ b/cde/programs/dtudcfonted/dtgpftobdf/gpftobdf.c @@ -350,7 +350,7 @@ static char *readfontfile( fname ) char *fname; { int fd; - char *fp; + char *fp = NULL; struct stat stat; fd = open( fname,O_RDONLY ); @@ -390,6 +390,7 @@ char *fname; if ( read( fd, fp, stat.st_size ) < 0 ) { USAGE("dtgpftobdf: can't read file.\n" ); close( fd ); + free(fp); return ( char * )-1; } } else { @@ -864,9 +865,9 @@ unsigned int *fplistNum; res->value = wkp->value; } } - wklp->name = (CARD32)fpropvnPtr + wkp->name; + wklp->name = (CARD32) (intptr_t) fpropvnPtr + wkp->name; if (wkp->indirect == TRUE) { - wklp->value = (INT32)fpropvnPtr + wkp->value; + wklp->value = (INT32) (intptr_t) fpropvnPtr + wkp->value; } else { wklp->value = wkp->value; } @@ -942,12 +943,12 @@ PropTmp *proptmp; f = proptmp->psize.value / 10.0; if ( ( proptmp->psize.value % 10 ) != 0 ) { - sprintf( buf1,"%.1f",f ); + snprintf( buf1, sizeof(buf1), "%.1f",f ); } else { - sprintf(buf1,"%.0f",f); + snprintf( buf1, sizeof(buf1), "%.0f",f); } k = ( ( proptmp->resolution.value * 72.27 ) / 100.0 ) + 1; - sprintf( buf2, "%d %d", k, k ); + snprintf( buf2, sizeof(buf2), "%d %d", k, k ); fprintf( stdout,"SIZE %s %s\n", buf1, buf2 ); return; } @@ -964,26 +965,26 @@ unsigned int fplistNum; int i, k; bufp = buf; - k = sprintf( bufp,"STARTPROPERTIES %d\n", fplistNum+3 ); + k = snprintf( bufp, sizeof(buf), "STARTPROPERTIES %d\n", fplistNum+3 ); bufp += k; - k = sprintf( bufp, "FONT_ASCENT %d\n", fip->fontAscent ); + k = snprintf( bufp, sizeof(buf) - (bufp - buf), "FONT_ASCENT %d\n", fip->fontAscent ); bufp += k; - k = sprintf( bufp, "FONT_DESCENT %d\n", fip->fontDescent ); + k = snprintf( bufp, sizeof(buf) - (bufp - buf), "FONT_DESCENT %d\n", fip->fontDescent ); bufp += k; - k = sprintf( bufp, "DEFAULT_CHAR %d\n", fip->chDefault ); + k = snprintf( bufp, sizeof(buf) - (bufp - buf), "DEFAULT_CHAR %d\n", fip->chDefault ); bufp += k; wkp = fplistPtr; for ( i = 0; i < fplistNum; i++ ) { if ( wkp->indirect == TRUE ) { - k = sprintf( bufp, "%s \"%s\"\n", wkp->name, wkp->value ); + k = snprintf( bufp, sizeof(buf) - (bufp - buf), "%s \"%s\"\n", (char *) (intptr_t) wkp->name, (char *) (intptr_t) wkp->value ); bufp += k; } else { - k = sprintf( bufp, "%s %d\n", wkp->name, wkp->value ); + k = snprintf( bufp, sizeof(buf) - (bufp - buf), "%s %d\n", (char *) (intptr_t) wkp->name, wkp->value ); bufp += k; } wkp++; } - k = sprintf( bufp, "ENDPROPERTIES\n" ); + k = snprintf( bufp, sizeof(buf) - (bufp - buf), "ENDPROPERTIES\n" ); bufp += k; *bufp = '\0'; fprintf( stdout, "%s", buf ); @@ -1094,7 +1095,7 @@ unsigned int glyphPad; for ( i = 0; i < bbh; i++ ) { bufp = buf; for ( j = 0; j < bml; j++ ) { - sprintf( bufp, "%s", cvtp[(unsigned char)glyph[j]] ); + sprintf( bufp, "%s", (char *) cvtp[(unsigned char)glyph[j]] ); bufp += 2; } fprintf( stdout, "%.*s\n", bml*2, buf ); diff --git a/cde/programs/dtudcfonted/dtgpftocpf/gpftocpf.c b/cde/programs/dtudcfonted/dtgpftocpf/gpftocpf.c index 92474c97..0a1af2e7 100644 --- a/cde/programs/dtudcfonted/dtgpftocpf/gpftocpf.c +++ b/cde/programs/dtudcfonted/dtgpftocpf/gpftocpf.c @@ -250,7 +250,7 @@ char *argv[]; } } - if ( Head.in_file == NULL && xlfdname == '\0' ) { + if ( Head.in_file == NULL && xlfdname == NULL ) { if ( code_area & SYSTM ) { USAGE1("%s : The GPF output file name cannot be omitted.\n", argv[0] ); } else { @@ -605,23 +605,20 @@ FalGlyphRegion *gr ; if( (code_num >= gr[i].start) && (code_num <= gr[i].end) ) return( code_num ); } - err_flg = 1 ; } - if (err_flg) { - switch( mode ) { - case 0: + + switch( mode ) { + case 0: USAGE2("%s : The specification of the extract start code is improper.\"%s\"¡¥\n", prog_name, code_str); break; - case 1: + case 1: USAGE2("%s : The specification of the extract end code is improper.\"%s\"¡¥\n", prog_name, code_str); break; - default: + default: USAGE2("%s : The specification of the extract code is improper.\"%s\"¡¥\n", prog_name, code_str); - } - return(-1); } return(-1); } diff --git a/cde/programs/dtudcfonted/libfal/_fallcDB.c b/cde/programs/dtudcfonted/libfal/_fallcDB.c index a89aab8c..747f1894 100644 --- a/cde/programs/dtudcfonted/libfal/_fallcDB.c +++ b/cde/programs/dtudcfonted/libfal/_fallcDB.c @@ -623,6 +623,7 @@ store_to_database(db) if(new->name){ Xfree(new->name); } + Xfree(new); } if(parse_info.value){ if(*parse_info.value){ diff --git a/cde/programs/dtudcfonted/libfal/_fallcGeneric.c b/cde/programs/dtudcfonted/libfal/_fallcGeneric.c index 9e76fe55..287dd1e4 100644 --- a/cde/programs/dtudcfonted/libfal/_fallcGeneric.c +++ b/cde/programs/dtudcfonted/libfal/_fallcGeneric.c @@ -457,8 +457,8 @@ XLCdGenericPart *gen; _fallcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num); dbg_printValue(name,value,num); if (num > 0) { - strcpy(cset_name,value[0]); - sprintf(name, "%s.%s", csd , "side"); + snprintf(cset_name, sizeof(cset_name), "%s", value[0]); + snprintf(name, sizeof(name), "%s.%s", csd , "side"); _fallcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num); if (num > 0) { dbg_printValue(name,value,num); @@ -495,21 +495,21 @@ XLCdGenericPart *gen; /* side */ charsetd->side = side ; /* length */ - sprintf(name, "%s.%s", csd , "length"); + snprintf(name, sizeof(name), "%s.%s", csd , "length"); _fallcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num); if (num > 0) { dbg_printValue(name,value,num); charsetd->char_size = atoi(value[0]); } /* gc_number */ - sprintf(name, "%s.%s", csd , "gc_number"); + snprintf(name, sizeof(name), "%s.%s", csd , "gc_number"); _fallcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num); if (num > 0) { dbg_printValue(name,value,num); charsetd->set_size = atoi(value[0]); } /* string_encoding */ - sprintf(name, "%s.%s", csd , "string_encoding"); + snprintf(name, sizeof(name), "%s.%s", csd , "string_encoding"); _fallcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num); if (num > 0) { dbg_printValue(name,value,num); @@ -520,7 +520,7 @@ XLCdGenericPart *gen; } } /* sequence */ - sprintf(name, "%s.%s", csd , "sequence"); + snprintf(name, sizeof(name), "%s.%s", csd , "sequence"); _fallcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num); if (num > 0) { dbg_printValue(name,value,num); @@ -537,7 +537,7 @@ XLCdGenericPart *gen; string_to_encoding(value[0],tmp); } /* encoding_name */ - sprintf(name, "%s.%s", csd , "encoding_name"); + snprintf(name, sizeof(name), "%s.%s", csd , "encoding_name"); _fallcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num); if (num > 0) { dbg_printValue(name,value,num); @@ -698,6 +698,7 @@ int num; if(strchr(value[0],':')){ ret->name = (char *)Xmalloc(strlen(value[0])+1); if(ret->name == NULL){ + XFree(ret); return(NULL); } strcpy(ret->name,value[0]); @@ -706,24 +707,27 @@ int num; ptr++; if( !_fallcNCompareISOLatin1(ptr, "none", 4) ){ ret->side = XlcNONE ; - sprintf(cset_name,"%s:%s",ret->name,"none"); + snprintf(cset_name,sizeof(cset_name),"%s:%s",ret->name,"none"); } else if( !_fallcNCompareISOLatin1(ptr, "GL", 2) ){ ret->side = XlcGL ; - sprintf(cset_name,"%s:%s",ret->name,"GL"); + snprintf(cset_name,sizeof(cset_name),"%s:%s",ret->name,"GL"); } else { ret->side = XlcGR ; - sprintf(cset_name,"%s:%s",ret->name,"GR"); + snprintf(cset_name,sizeof(cset_name),"%s:%s",ret->name,"GR"); } } else { ret->name = (char *)Xmalloc(strlen(value[0])+1); if(ret->name == NULL){ + XFree(ret); return(NULL); } strcpy(ret->name,value[0]); } ret->area = (FontScope)Xmalloc((num - 1)*sizeof(FontScopeRec)); if(ret->area == NULL){ + XFree(ret->name); + XFree(ret); return(NULL); } ret->area_num = num - 1; @@ -735,7 +739,10 @@ int num; if(new){ tmp = (char *)Xmalloc(strlen(cset_name)+1); if(tmp == NULL){ - return 0; + XFree(ret->area); + XFree(ret->name); + XFree(ret); + return NULL; } strcpy(tmp,cset_name); ret->charset->name = tmp; diff --git a/cde/programs/dtudcfonted/libfal/_fallcWrap.c b/cde/programs/dtudcfonted/libfal/_fallcWrap.c index 39635b89..97fde4cd 100644 --- a/cde/programs/dtudcfonted/libfal/_fallcWrap.c +++ b/cde/programs/dtudcfonted/libfal/_fallcWrap.c @@ -79,6 +79,7 @@ from the X Consortium. * Katsuhisa Yano TOSHIBA Corp. */ +#include #include "_fallibint.h" #include "_fallcint.h" #if defined(linux) @@ -499,12 +500,12 @@ _fallcCopyFromArg(src, dst, size) *((long *) dst) = (long) src; #ifdef LONG64 else if (size == sizeof(int)) - *((int *) dst) = (int) src; + *((int *) dst) = (int) (intptr_t) src; #endif else if (size == sizeof(short)) - *((short *) dst) = (short) src; + *((short *) dst) = (short) (intptr_t) src; else if (size == sizeof(char)) - *((char *) dst) = (char) src; + *((char *) dst) = (char) (intptr_t) src; else if (size == sizeof(XPointer)) *((XPointer *) dst) = (XPointer) src; else if (size > sizeof(XPointer)) diff --git a/cde/programs/dtudcfonted/libfal/_falomGeneric.c b/cde/programs/dtudcfonted/libfal/_falomGeneric.c index 2c8a60ec..5cc7bbab 100644 --- a/cde/programs/dtudcfonted/libfal/_falomGeneric.c +++ b/cde/programs/dtudcfonted/libfal/_falomGeneric.c @@ -625,19 +625,20 @@ static char } } - if(field_num < CHARSET_ENCODING_FIELD) + if(field_num < CHARSET_ENCODING_FIELD) { + Xfree(pattern); return NULL; + } /* Pixel Size field : fields[6] */ for(ptr = fields[PIXEL_SIZE_FIELD - 1] ; ptr && *ptr; ptr++) { if(!isdigit(*ptr)) { - if(pattern) - Xfree(pattern); + Xfree(pattern); return NULL; } } pixel_size = atoi(fields[PIXEL_SIZE_FIELD - 1]); - sprintf(str_pixel, "[ 0 ~%d %d 0 ]", pixel_size, pixel_size); + snprintf(str_pixel, sizeof(str_pixel), "[ 0 ~%d %d 0 ]", pixel_size, pixel_size); fields[6] = str_pixel; /* Point Size field : fields[7] */ @@ -647,7 +648,7 @@ static char rotate_font[0] = '\0'; for(field_num = 0 ; field_num < CHARSET_ENCODING_FIELD && fields[field_num] ; field_num++) { - sprintf(rotate_font, "%s-%s", rotate_font, fields[field_num]); + snprintf(rotate_font, sizeof(rotate_font), "%s-%s", rotate_font, fields[field_num]); } if(pattern) @@ -713,7 +714,6 @@ parse_omit_name(oc, font_data, pattern) if(is_match_charset(font_data, pattern) == True) { strcpy(buf, pattern); - length = strlen(pattern); if (font_name = get_font_name(oc, buf)) { font_data->xlfd_name = (char *)Xmalloc(strlen(font_name) + 1); if(font_data->xlfd_name == NULL) { @@ -1674,8 +1674,10 @@ char **value; bufptr++ ; } font_data->name = (char *) Xmalloc(len + 1); - if (font_data->name == NULL) + if (font_data->name == NULL) { + XFree(font_data); return NULL; + } strncpy(font_data->name, buf,len); font_data->name[len] = 0; if (bufptr && _fallcCompareISOLatin1(bufptr, "GL") == 0) @@ -1726,7 +1728,7 @@ int num; char **value, buf[BUFSIZ], *bufptr; int count,i; - sprintf(buf, "fs%d.font.vertical_map", num); + snprintf(buf, sizeof(buf), "fs%d.font.vertical_map", num); _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); if (count > 0){ dbg_printValue(buf,value,count); @@ -1734,7 +1736,7 @@ int num; font_set->vmap = falread_EncodingInfo(count,value); } - sprintf(buf, "fs%d.font.vertical_rotate", num); + snprintf(buf, sizeof(buf), "fs%d.font.vertical_rotate", num); _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); if (count > 0){ dbg_printValue(buf,value,count); @@ -1771,11 +1773,11 @@ init_om(om) for (num = 0; ; num++) { - sprintf(buf, "fs%d.charset.name", num); + snprintf(buf, sizeof(buf), "fs%d.charset.name", num); _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); if( count < 1){ - sprintf(buf, "fs%d.charset", num); + snprintf(buf, sizeof(buf), "fs%d.charset", num); _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); if (count < 1) break; @@ -1794,7 +1796,7 @@ init_om(om) while (count-- > 0){ *charset_list++ = _fallcGetCharSet(*value++); } - sprintf(buf, "fs%d.charset.udc_area", num); + snprintf(buf, sizeof(buf), "fs%d.charset.udc_area", num); _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); if( count > 0){ UDCArea udc; @@ -1817,10 +1819,10 @@ init_om(om) } } - sprintf(buf, "fs%d.font.primary", num); + snprintf(buf, sizeof(buf), "fs%d.font.primary", num); _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); if (count < 1){ - sprintf(buf, "fs%d.font", num); + snprintf(buf, sizeof(buf), "fs%d.font", num); _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); if (count < 1) return False; @@ -1833,7 +1835,7 @@ init_om(om) data->font_data = font_data; data->font_data_count = count; - sprintf(buf, "fs%d.font.substitute", num); + snprintf(buf, sizeof(buf), "fs%d.font.substitute", num); _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); if (count > 0){ font_data = falread_EncodingInfo(count,value); @@ -1842,7 +1844,7 @@ init_om(om) data->substitute = font_data; data->substitute_num = count; } else { - sprintf(buf, "fs%d.font", num); + snprintf(buf, sizeof(buf), "fs%d.font", num); _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); if (count < 1) { data->substitute = NULL; diff --git a/cde/programs/dtudcfonted/libfal/_faludcInf.c b/cde/programs/dtudcfonted/libfal/_faludcInf.c index 786fbc93..f41e2a16 100644 --- a/cde/programs/dtudcfonted/libfal/_faludcInf.c +++ b/cde/programs/dtudcfonted/libfal/_faludcInf.c @@ -32,6 +32,7 @@ * */ #include +#include #include #include "syncx.h" #include "_fallibint.h" @@ -410,7 +411,7 @@ unsigned long *codepoint; memset(dst,0,25); - lcd = (XLCd)_fallcGenericLoader(locale); + lcd = (XLCd) (uintptr_t) _fallcGenericLoader(locale); fal_gi_to_vgi(lcd,locale,charset_str,codeset, glyph_index,&glyph_index,charsetname); @@ -439,9 +440,9 @@ unsigned long *codepoint; if( falnon_standard(lcd,charset)) { falmake_none_standard(from,charset,src); } else if(charset->ct_sequence){ - sprintf((char *)from,"%s%s",charset->ct_sequence,src); + snprintf((char *)from, sizeof(from32), "%s%s", charset->ct_sequence,src); } else { - sprintf((char *)from,"%s\0",src); + snprintf((char *)from, sizeof(from32), "%s", src); } /* compound text -> multi byte */ conv = _fallcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNMultiByte); @@ -640,7 +641,7 @@ int *num_gi; dst = (unsigned char *)to32; memset(dst,0,25); - lcd = (XLCd)_fallcGenericLoader(locale); + lcd = (XLCd) (uintptr_t) _fallcGenericLoader(locale); for(i=0,j=0;i<4;i++){ byte = getbyte(codepoint,i); @@ -650,7 +651,7 @@ int *num_gi; } } src[j] = 0; - sprintf((char *)from,"%s\0",src); + snprintf((char *)from, sizeof(from32), "%s", src); /* multi byte -> vgi */ conv = _fallcOpenConverter(lcd, XlcNMultiByte, lcd, XlcNCharSet); from_left = strlen((char *)from); @@ -674,13 +675,14 @@ int *num_gi; _fallcDestroyLC(lcd); *gi = (FalGIInf *)Xmalloc(sizeof(FalGIInf)); - (*gi)->charset_str = (char *)Xmalloc(strlen(charsetname)+1); - strcpy((*gi)->charset_str,charsetname); - (*gi)->glyph_index = glyph; if(*gi == NULL){ fal_utyerrno = 0x03 ; return(FAL_ERROR); } + (*gi)->charset_str = (char *)Xmalloc(strlen(charsetname)+1); + strcpy((*gi)->charset_str,charsetname); + (*gi)->glyph_index = glyph; + *num_gi = 1; return(0); } diff --git a/cde/programs/dtudcfonted/libfal/falfont.c b/cde/programs/dtudcfonted/libfal/falfont.c index f605a55c..7b0c3769 100644 --- a/cde/programs/dtudcfonted/libfal/falfont.c +++ b/cde/programs/dtudcfonted/libfal/falfont.c @@ -343,6 +343,10 @@ int lockflag; if ( !(finf->fname = (char *)strdup( openfontfile )) ) { fal_seterrcode( _FAL_MALOC_ER, 0, FAL_ERR_MALLOC , FAL_FUNCNUM_OPNFNT ) ; + free( openfontfile ); + free( finf ); + free( buf ); + close( fd ); return (FalFontID)FAL_ERROR; } @@ -501,9 +505,7 @@ int lockflag; } set_errfile_str( fal_err_file_buf, finf->fname ) ; - if ( finf->fname ) { - free( finf->fname ); - } + free( finf->fname ); if ( finf->buf != NULL ) { #if defined( SVR4 ) if ( finf->ismmap == TRUE ) { @@ -520,15 +522,10 @@ int lockflag; close( finf->fd ); #endif - if ( finf->sptnBuf ) { - free( finf->sptnBuf ); - } - if ( finf->dptnBuf ){ - free( finf->dptnBuf ); - } - if ( finf->dbuf ) { - free( finf->dbuf ); - } + free( finf->sptnBuf ); + free( finf->dptnBuf ); + free( finf->dbuf ); + free ( finf ); } if ( lockflag == 1 ) { @@ -1069,15 +1066,9 @@ FalFontDataList *list; if ( list->list != NULL ) { for ( i = 0; i < list->num; i++ ) { /* free a structure's character of "FalFontData()" */ - if ( list->list[i].xlfdname ) { - free( list->list[i].xlfdname ); - } - if ( list->list[i].style.name ) { - free( list->list[i].style.name ); - } - if ( list->list[i].shape.name ) { - free( list->list[i].shape.name ); - } + free( list->list[i].xlfdname ); + free( list->list[i].style.name ); + free( list->list[i].shape.name ); FAL_FREE_FONTLIST_OPTION( list ) ; } /* free a structure's array of "FalFontData()" */ @@ -1143,15 +1134,9 @@ fal_clear_data(tmp) FalFontData *tmp; { /* search a character */ - if ( tmp->xlfdname != NULL ) { - free(tmp->xlfdname); - } - if (tmp->style.name != NULL) { - free(tmp->style.name); - } - if (tmp->shape.name != NULL) { - free(tmp->shape.name); - } + free(tmp->xlfdname); + free(tmp->style.name); + free(tmp->shape.name); FAL_CLEAR_DATA_OPTION( tmp ) ; memset(tmp, 0, sizeof(*tmp)); return 0 ; @@ -2296,6 +2281,7 @@ FalFontPath *pathlist ; fal_clear_font_path( pathlist ); fal_utyerror = _FAL_MALOC_ER; fal_utyerrno = FAL_ERR_MALLOC ; + free(path); return FAL_ERROR ; } pathlist->path = plist; @@ -2982,6 +2968,7 @@ int islock ; if( (flist[cnt] = (FontIDInfo *)malloc( sizeof(FontIDInfo) )) == NULL ) { fal_utyerror = _FAL_MALOC_ER ; fal_utyerrno = FAL_ERR_MALLOC ; + free(flist); return FAL_ERROR ; } flist[cnt]->fid = fid ; diff --git a/cde/programs/dtudcfonted/libfal/readpcf.c b/cde/programs/dtudcfonted/libfal/readpcf.c index a7ff8728..2d19c6ba 100644 --- a/cde/programs/dtudcfonted/libfal/readpcf.c +++ b/cde/programs/dtudcfonted/libfal/readpcf.c @@ -778,7 +778,7 @@ char *propname; if ( *buffer) { /* isStringProp */ return( propstr + getINT32( (unsigned char *)(buffer + 1), (CARD32)format) ); }else{ - return((char *)getINT32( (unsigned char *)(buffer + 1), (CARD32)format) ); + return((char *)(intptr_t)getINT32( (unsigned char *)(buffer + 1), (CARD32)format) ); } } buffer += 5 ; /* isStringProp + value */ @@ -800,7 +800,7 @@ FalFontData *databuff ; caddr_t stprop ; int lb, rb, as, ds ; char *propptr ; - char *fnt, *fam ; + char *fnt = NULL, *fam ; int nprops, bitmapSize, num_chars ; @@ -863,6 +863,7 @@ FalFontData *databuff ; return 0; Bail: + free(fnt); return -1; } @@ -890,7 +891,7 @@ char *propname; if( ProcRec->indirect ){ return( propstr + ProcRec->value ) ; }else{ - return( (char *)ProcRec->value ) ; + return( (char *) (intptr_t) ProcRec->value ) ; } } } diff --git a/cde/programs/dtudcfonted/libfuty/oakfuty.c b/cde/programs/dtudcfonted/libfuty/oakfuty.c index 7c37bc8a..5d51eee8 100644 --- a/cde/programs/dtudcfonted/libfuty/oakfuty.c +++ b/cde/programs/dtudcfonted/libfuty/oakfuty.c @@ -86,7 +86,9 @@ char *buf; char *p; unsigned int getstat = 0; - fgets(buf, BUFSIZE, head->input); + if (NULL == fgets(buf, BUFSIZE, head->input)) { + return(BDF_INVAL); + } p = buf; SCAN_TO_NONSP(p) @@ -1151,6 +1153,7 @@ char *wr_file ; if( read(rfd, buf, statbuf.st_size) != statbuf.st_size ){ close(wfd) ; close(rfd) ; + free(buf) ; return -1 ; } #if defined( SVR4 ) @@ -1474,6 +1477,7 @@ char *com; save_name, com ); Unlink_Tmpfile ( save_name, com ); Unlink_Tmpfile ( tmp_name, com ); + free(save_name); return( (put_file_create_err_msg == DEVICE_FAIL)? put_file_create_err_msg : rtn ); } @@ -1490,6 +1494,7 @@ char *com; Unlink_Tmpfile ( tmp_name, com ); Unlink_Tmpfile ( save_name, com ); } + free(save_name); return( (put_file_create_err_msg == DEVICE_FAIL)? put_file_create_err_msg : rtn ); } @@ -1498,6 +1503,7 @@ char *com; ret_val += Unlink_Tmpfile ( tmp_name, com ); ret_val += Unlink_Tmpfile ( save_name, com ); + free(save_name); return( (ret_val)? 1 : 0 ); } @@ -1658,6 +1664,7 @@ char *cmd; } FreeString( cmd_path ) ; } + free(cmd_path); AllocString( cmd_path, path, NULL ) ; AddString( cmd_path, "/", NULL ) ; AddString( cmd_path, cmd, NULL ) ; @@ -1697,10 +1704,12 @@ char *cmd ; } if( stat( pbuf, &statbuf ) ){ USAGE2("%s: There is not \"%s\" command.\n", com, cmd ) ; + free(pbuf); return STAT_ERROR ; } if( !(statbuf.st_mode & S_IXUSR) ){ USAGE2("%s: \"%s\" command don't have permission to execute.\n", com, cmd ) ; + free(pbuf); return STAT_ERROR ; } }else{ diff --git a/cde/programs/dtudcfonted/mtfgui.c b/cde/programs/dtudcfonted/mtfgui.c index 08d40812..a080f8c6 100644 --- a/cde/programs/dtudcfonted/mtfgui.c +++ b/cde/programs/dtudcfonted/mtfgui.c @@ -460,10 +460,10 @@ Widget owner; AddLeftAttachWidget( wgeStaT_disp[i], wgeStaT_list[i], 0 ) ; XtAddEventHandler( wgeStaT_list[i], ButtonPressMask|ButtonReleaseMask, - False, EHeStaT_list, (XtPointer)i ); + False, EHeStaT_list, (XtPointer) (intptr_t) i ); XtAddEventHandler( wgeStaT_disp[i], ButtonPressMask|ButtonReleaseMask, - False, EHeStaT_list, (XtPointer)i ); + False, EHeStaT_list, (XtPointer) (intptr_t) i ); if (i==0){ XtVaGetValues(wgeStaT_disp[i], @@ -579,7 +579,7 @@ int code; char str[8]; if (! code){ - str[0] = NULL; + str[0] = '\0'; } else{ sprintf( str, "%4x:", code ); diff --git a/cde/programs/dtudcfonted/util.c b/cde/programs/dtudcfonted/util.c index 31fbb00b..7eb639fa 100644 --- a/cde/programs/dtudcfonted/util.c +++ b/cde/programs/dtudcfonted/util.c @@ -345,7 +345,7 @@ int buttons_cnt; if (strchr(LABEL(i), NMNIC(i))){ sprintf(buf, "%s", LABEL(i)); }else{ - sprintf(buf, "%s(%c)", LABEL(i), NMNIC(i)); + sprintf(buf, "%s(%ld)", LABEL(i), NMNIC(i)); } xms = XmStringCreateLocalized(buf); XtSetArg(args[n],XmNlabelString, xms); n++; @@ -515,7 +515,7 @@ int val; XtSetArg(arg[n], XmNleftOffset, (XtArgVal)resource.draw_lftoff); n++; drawarea = XmCreateDrawingArea(owner, name, arg, n); XtManageChild( drawarea ); - XtAddEventHandler(drawarea, ExposureMask, FALSE, proc, (XtPointer)val); + XtAddEventHandler(drawarea, ExposureMask, FALSE, proc, (XtPointer) (intptr_t) val); return(drawarea); } -- 2.25.1