Skip to content

Commit

Permalink
Addressed new coverity-scan results
Browse files Browse the repository at this point in the history
  • Loading branch information
DanBloomberg committed Jul 13, 2024
1 parent bf127eb commit 0cadcdf
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/bmpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ RGBA_QUAD *pquad;
ncolors = 2;
cta = (l_uint8 *)bwmap;
} else { /* d = 2,4,8; use a grayscale output colormap */
ncolors = 1 << fdepth;
ncolors = 1 << d;
cmaplen = ncolors * sizeof(RGBA_QUAD);
heapcm = 1;
cta = (l_uint8 *)LEPT_CALLOC(cmaplen, 1);
Expand Down
4 changes: 2 additions & 2 deletions src/boxbasic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1954,7 +1954,7 @@ FILE *fp;
ret = boxaaWriteStream(fp, baa);
fputc('\0', fp);
fclose(fp);
*psize = *psize - 1;
if (*psize > 0) *psize = *psize - 1;
#else
L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
#ifdef _WIN32
Expand Down Expand Up @@ -2235,7 +2235,7 @@ FILE *fp;
ret = boxaWriteStream(fp, boxa);
fputc('\0', fp);
fclose(fp);
*psize = *psize - 1;
if (*psize > 0) *psize = *psize - 1;
#else
L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
#ifdef _WIN32
Expand Down
2 changes: 1 addition & 1 deletion src/colormap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1948,7 +1948,7 @@ FILE *fp;
ret = pixcmapWriteStream(fp, cmap);
fputc('\0', fp);
fclose(fp);
*psize = *psize - 1;
if (*psize > 0) *psize = *psize - 1;
#else
L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
#ifdef _WIN32
Expand Down
4 changes: 2 additions & 2 deletions src/dewarp1.c
Original file line number Diff line number Diff line change
Expand Up @@ -1385,7 +1385,7 @@ FILE *fp;
ret = dewarpWriteStream(fp, dew);
fputc('\0', fp);
fclose(fp);
*psize = *psize - 1;
if (*psize > 0) *psize = *psize - 1;
#else
L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
#ifdef _WIN32
Expand Down Expand Up @@ -1656,7 +1656,7 @@ FILE *fp;
ret = dewarpaWriteStream(fp, dewa);
fputc('\0', fp);
fclose(fp);
*psize = *psize - 1;
if (*psize > 0) *psize = *psize - 1;
#else
L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
#ifdef _WIN32
Expand Down
4 changes: 2 additions & 2 deletions src/dnabasic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ FILE *fp;
ret = l_dnaWriteStream(fp, da);
fputc('\0', fp);
fclose(fp);
*psize = *psize - 1;
if (*psize > 0) *psize = *psize - 1;
#else
L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
#ifdef _WIN32
Expand Down Expand Up @@ -1787,7 +1787,7 @@ FILE *fp;
ret = l_dnaaWriteStream(fp, daa);
fputc('\0', fp);
fclose(fp);
*psize = *psize - 1;
if (*psize > 0) *psize = *psize - 1;
#else
L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
#ifdef _WIN32
Expand Down
2 changes: 1 addition & 1 deletion src/fpix1.c
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ FILE *fp;
ret = fpixWriteStream(fp, fpix);
fputc('\0', fp);
fclose(fp);
*psize = *psize - 1;
if (*psize > 0) *psize = *psize - 1;
#else
L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
#ifdef _WIN32
Expand Down
2 changes: 1 addition & 1 deletion src/jpegio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ FILE *fp;
ret = pixWriteStreamJpeg(fp, pix, quality, progressive);
fputc('\0', fp);
fclose(fp);
*psize = *psize - 1;
if (*psize > 0) *psize = *psize - 1;
#else
L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
#ifdef _WIN32
Expand Down
4 changes: 2 additions & 2 deletions src/numabasic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ FILE *fp;
ret = numaWriteStream(fp, na);
fputc('\0', fp);
fclose(fp);
*psize = *psize - 1;
if (*psize > 0) *psize = *psize - 1;
#else
L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
#ifdef _WIN32
Expand Down Expand Up @@ -1946,7 +1946,7 @@ FILE *fp;
ret = numaaWriteStream(fp, naa);
fputc('\0', fp);
fclose(fp);
*psize = *psize - 1;
if (*psize > 0) *psize = *psize - 1;
#else
L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
#ifdef _WIN32
Expand Down
20 changes: 11 additions & 9 deletions src/pix2.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ pixGetBlackOrWhiteVal(PIX *pixs,
l_int32 op,
l_uint32 *pval)
{
l_int32 d, val;
l_int32 d, index;
PIXCMAP *cmap;

if (!pval)
Expand All @@ -736,17 +736,17 @@ PIXCMAP *cmap;
if (!cmap) {
if ((d == 1 && op == L_GET_WHITE_VAL) ||
(d > 1 && op == L_GET_BLACK_VAL)) { /* min val */
val = 0;
*pval = 0;
} else { /* max val */
val = (d == 32) ? 0xffffff00 : (1 << d) - 1;
*pval = (d == 32) ? 0xffffff00 : (1 << d) - 1;
}
} else { /* handle colormap */
if (op == L_GET_BLACK_VAL)
pixcmapAddBlackOrWhite(cmap, 0, &val);
pixcmapAddBlackOrWhite(cmap, 0, &index);
else /* L_GET_WHITE_VAL */
pixcmapAddBlackOrWhite(cmap, 1, &val);
pixcmapAddBlackOrWhite(cmap, 1, &index);
*pval = index;
}
*pval = val;

return 0;
}
Expand Down Expand Up @@ -1164,7 +1164,8 @@ pixSetInRectArbitrary(PIX *pix,
BOX *box,
l_uint32 val)
{
l_int32 n, x, y, xstart, xend, ystart, yend, bw, bh, w, h, d, wpl, maxval;
l_int32 n, x, y, xstart, xend, ystart, yend, bw, bh, w, h, d, wpl;
l_uint32 maxval;
l_uint32 *data, *line;
BOX *boxc;
PIXCMAP *cmap;
Expand Down Expand Up @@ -1879,8 +1880,9 @@ pixAddBorderGeneral(PIX *pixs,
l_int32 bot,
l_uint32 val)
{
l_int32 ws, hs, wd, hd, d, maxval, op;
PIX *pixd;
l_int32 ws, hs, wd, hd, d, op;
l_uint32 maxval;
PIX *pixd;

if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", __func__, NULL);
Expand Down
4 changes: 2 additions & 2 deletions src/pixabasic.c
Original file line number Diff line number Diff line change
Expand Up @@ -2744,7 +2744,7 @@ FILE *fp;
ret = pixaWriteStream(fp, pixa);
fputc('\0', fp);
fclose(fp);
*psize = *psize - 1;
if (*psize > 0) *psize = *psize - 1;
#else
L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
#ifdef _WIN32
Expand Down Expand Up @@ -3114,7 +3114,7 @@ FILE *fp;
ret = pixaaWriteStream(fp, paa);
fputc('\0', fp);
fclose(fp);
*psize = *psize - 1;
if (*psize > 0) *psize = *psize - 1;
#else
L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
#ifdef _WIN32
Expand Down
2 changes: 1 addition & 1 deletion src/pixcomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1868,7 +1868,7 @@ FILE *fp;
ret = pixacompWriteStream(fp, pixac);
fputc('\0', fp);
fclose(fp);
*psize = *psize - 1;
if (*psize > 0) *psize = *psize - 1;
#else
L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
#ifdef _WIN32
Expand Down
4 changes: 2 additions & 2 deletions src/pnmio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ FILE *fp;
ret = pixWriteStreamPnm(fp, pix);
fputc('\0', fp);
fclose(fp);
*psize = *psize - 1;
if (*psize > 0) *psize = *psize - 1;
#else
L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
#ifdef _WIN32
Expand Down Expand Up @@ -1293,7 +1293,7 @@ FILE *fp;
ret = pixWriteStreamPam(fp, pix);
fputc('\0', fp);
fclose(fp);
*psize = *psize - 1;
if (*psize > 0) *psize = *psize - 1;
#else
L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
#ifdef _WIN32
Expand Down
4 changes: 2 additions & 2 deletions src/ptabasic.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ FILE *fp;
ret = ptaWriteStream(fp, pta, type);
fputc('\0', fp);
fclose(fp);
*psize = *psize - 1;
if (*psize > 0) *psize = *psize - 1;
#else
L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
#ifdef _WIN32
Expand Down Expand Up @@ -1492,7 +1492,7 @@ FILE *fp;
ret = ptaaWriteStream(fp, ptaa, type);
fputc('\0', fp);
fclose(fp);
*psize = *psize - 1;
if (*psize > 0) *psize = *psize - 1;
#else
L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
#ifdef _WIN32
Expand Down
2 changes: 1 addition & 1 deletion src/recogbasic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ FILE *fp;
ret = recogWriteStream(fp, recog);
fputc('\0', fp);
fclose(fp);
*psize = *psize - 1;
if (*psize > 0) *psize = *psize - 1;
#else
L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
#ifdef _WIN32
Expand Down
2 changes: 1 addition & 1 deletion src/sarray1.c
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,7 @@ FILE *fp;
ret = sarrayWriteStream(fp, sa);
fputc('\0', fp);
fclose(fp);
*psize = *psize - 1;
if (*psize > 0) *psize = *psize - 1;
#else
L_INFO("no fmemopen API --> work-around: write to temp file\n", __func__);
#ifdef _WIN32
Expand Down
13 changes: 8 additions & 5 deletions version-notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,15 @@ <h2 align=center> <IMG SRC="moller52.jpg" border=1 ALIGN_MIDDLE> </h2>
a specified resolution.
* Modified cleanpdf.c to use l_pdfRenderFiles().
* Source files changed: adaptmap.c affinecompose.c,
colormap.c, compare.c,
bmpio.c, boxbasic.c, colormap.c, compare.c,
dewarp1.c, dnabasic.c, fpix1.c,
gplot.c, grayquant.c, jbclass.c, jp2kheader.c,
jp2kheaderstub.c, jp2kio.c, libversions.c,
morphseq.c, pageseg.c partify.c, pdfapp.c, pdfio2.c, pixconv.c,
psio2.c, readfile.c, renderpdf.c,
sel1.c, utils2.c, writefile.c,
jp2kheaderstub.c, jp2kio.c, jpegio.c, libversions.c,
morphseq.c, numabasic.c, pageseg.c partify.c, pdfapp.c,
pdfio2.c, pix2.c, pixabasic.c, pixcomp.c, pixconv.c,
pnmio.c, psio2.c, ptabasic.c,
readfile.c, recogbasic.c, renderpdf.c,
sarray1.c, sel1.c, utils2.c, writefile.c,
allheaders.h, environ.h
* Prog files changed: alltests_reg.c, binmorph3_reg.c,
blend2_reg.c, cleanpdf.c, compressedpdf.c, croppdf.c,
Expand Down

0 comments on commit 0cadcdf

Please sign in to comment.