Skip to content

Commit ff8c565

Browse files
authored
Merge pull request #30 from william8000/fix-clobber-warning-1sep24
xvjpeg.c,xvpng.c: Fix gcc warnings on -Wclobbered
2 parents 8cd5e98 + d7b78d7 commit ff8c565

File tree

6 files changed

+18
-6
lines changed

6 files changed

+18
-6
lines changed

src/xv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,8 +1446,8 @@ static void parseResources(int argc, char **argv)
14461446
if (rd_flag("pic2split")) pic2split = def_int;
14471447
#endif
14481448
if (rd_flag("popupKludge")) winCtrPosKludge = def_int;
1449-
if (rd_str ("print")) strncpy(printCmd, def_str,
1450-
(size_t) PRINTCMDLEN);
1449+
if (rd_str ("print")) { strncpy(printCmd, def_str, (size_t) PRINTCMDLEN);
1450+
printCmd[ PRINTCMDLEN - 1 ] = '\0'; }
14511451
if (rd_flag("pscompress")) pscomp = def_int;
14521452
if (rd_flag("pspreview")) preview = def_int;
14531453
if (rd_flag("quick24") && def_int) conv24 = CONV24_FAST;

src/xvbrowse.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3710,6 +3710,7 @@ static void genIcon(BROWINFO *br, BFIL *bf)
37103710
if (UncompressFile(uncName, uncompname, filetype)) {
37113711
filetype = ReadFileType(uncompname);
37123712
strncpy(readname, uncompname, sizeof(readname) - 1);
3713+
readname[ sizeof(readname) - 1 ] = '\0';
37133714
}
37143715
else {
37153716
sprintf(str, "Couldn't uncompress file '%s'", bf->name);

src/xvjpeg.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,16 +507,20 @@ int LoadJFIF(char *fname, PICINFO *pinfo, int quick)
507507
struct my_error_mgr jerr;
508508
JSAMPROW rowptr[1];
509509
FILE *fp;
510-
const char *colorspace_name = "Color";
510+
const char *colorspace_name;
511511
byte *pic;
512512
long filesize;
513513
int i,w,h,bperpix,bperline,count;
514514

515515

516+
/* Initialize variables below instead of in the declarations above to avoid the warning */
517+
/* variable might be clobbered by 'longjmp' or 'vfork' [-Wclobbered] */
518+
516519
fbasename = BaseName(fname);
517520
pic = (byte *) NULL;
518521
comment = (char *) NULL;
519522
exifInfo = (byte *) NULL;
523+
colorspace_name = "Color";
520524

521525
pinfo->type = PIC8;
522526

@@ -552,7 +556,6 @@ int LoadJFIF(char *fname, PICINFO *pinfo, int quick)
552556
return 0;
553557
}
554558

555-
556559
jpeg_create_decompress(&cinfo);
557560
jpeg_set_marker_processor(&cinfo, JPEG_COM, xv_process_comment);
558561
jpeg_set_marker_processor(&cinfo, JPEG_APP1, xv_process_app1);

src/xvpds.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,21 +650,28 @@ int LoadPDS(char *fname, PICINFO *pinfo)
650650
*infobuff='\0';
651651
if (*spacecraft) {
652652
strncat(infobuff, spacecraft, sizeof(infobuff) - 1);
653+
infobuff[ sizeof(infobuff) - 1 ] = '\0';
653654
}
654655

655656
if (*target) {
656657
strncat(infobuff, ", ", sizeof(infobuff) - strlen(infobuff) - 1);
658+
infobuff[ sizeof(infobuff) - 1 ] = '\0';
657659
strncat(infobuff, target, sizeof(infobuff) - strlen(infobuff) - 1);
660+
infobuff[ sizeof(infobuff) - 1 ] = '\0';
658661
}
659662

660663
if (*filtname) {
661664
strncat(infobuff, ", ", sizeof(infobuff) - strlen(infobuff) - 1);
665+
infobuff[ sizeof(infobuff) - 1 ] = '\0';
662666
strncat(infobuff, filtname, sizeof(infobuff) - strlen(infobuff) - 1);
667+
infobuff[ sizeof(infobuff) - 1 ] = '\0';
663668
}
664669

665670
if (*itime) {
666671
strncat(infobuff, ", ", sizeof(infobuff) - strlen(infobuff) - 1);
672+
infobuff[ sizeof(infobuff) - 1 ] = '\0';
667673
strncat(infobuff, itime, sizeof(infobuff) - strlen(infobuff) - 1);
674+
infobuff[ sizeof(infobuff) - 1 ] = '\0';
668675
}
669676

670677
SetISTR(ISTR_WARNING, "%s", infobuff);

src/xvpng.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ int WritePNG(FILE *fp, byte *pic, int ptype, int w, int h, byte *rmap, byte *gma
431431
byte r1[256], g1[256], b1[256]; /* storage for deduped palette */
432432
byte pc2nc[256]; /* for duplicated-color remapping (1st level) */
433433
byte remap[256]; /* for bw/grayscale remapping (2nd level) */
434-
int i, j, numuniqcols=0, filter, linesize, pass;
434+
int i, j, numuniqcols, filter, linesize, pass;
435435
byte *p, *png_line;
436436
char software[256];
437437
char *savecmnt;
@@ -496,7 +496,7 @@ int WritePNG(FILE *fp, byte *pic, int ptype, int w, int h, byte *rmap, byte *gma
496496
_interlace_type = interCB.val ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE;
497497

498498
linesize = 0; /* quiet a compiler warning */
499-
499+
numuniqcols = 0;
500500

501501
/* GRR 20070331: remap palette to eliminate duplicated colors (as in
502502
* xvgifwr.c) */

src/xvtext.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ int TextView(const char *fname)
389389
#endif
390390

391391
strncpy(rfname, filename, sizeof(rfname) - 1);
392+
rfname[ sizeof(rfname) - 1 ] = '\0';
392393

393394
/* see if this file is compressed. if it is, uncompress it, and view
394395
the uncompressed version */

0 commit comments

Comments
 (0)