diff --git a/src/bmpio.c b/src/bmpio.c index 6da03d98e..b3c6bb5a6 100644 --- a/src/bmpio.c +++ b/src/bmpio.c @@ -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); diff --git a/src/boxbasic.c b/src/boxbasic.c index cbb485909..aaffbb16c 100644 --- a/src/boxbasic.c +++ b/src/boxbasic.c @@ -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 @@ -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 diff --git a/src/colormap.c b/src/colormap.c index f0a00c1a2..9533fe688 100644 --- a/src/colormap.c +++ b/src/colormap.c @@ -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 diff --git a/src/dewarp1.c b/src/dewarp1.c index 9013681cf..aa5e31319 100644 --- a/src/dewarp1.c +++ b/src/dewarp1.c @@ -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 @@ -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 diff --git a/src/dnabasic.c b/src/dnabasic.c index 1c19b556c..47b305779 100644 --- a/src/dnabasic.c +++ b/src/dnabasic.c @@ -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 @@ -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 diff --git a/src/fpix1.c b/src/fpix1.c index f5649c7a5..e0616fa18 100644 --- a/src/fpix1.c +++ b/src/fpix1.c @@ -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 diff --git a/src/jpegio.c b/src/jpegio.c index ab374117d..02b2a0b3c 100644 --- a/src/jpegio.c +++ b/src/jpegio.c @@ -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 diff --git a/src/numabasic.c b/src/numabasic.c index efc5c0af9..5138f987b 100644 --- a/src/numabasic.c +++ b/src/numabasic.c @@ -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 @@ -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 diff --git a/src/pix2.c b/src/pix2.c index 8d28db99c..487cebf7e 100644 --- a/src/pix2.c +++ b/src/pix2.c @@ -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) @@ -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; } @@ -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; @@ -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); diff --git a/src/pixabasic.c b/src/pixabasic.c index 8855e9fd9..97d28ca60 100644 --- a/src/pixabasic.c +++ b/src/pixabasic.c @@ -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 @@ -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 diff --git a/src/pixcomp.c b/src/pixcomp.c index 98c8e730d..5ec4ba644 100644 --- a/src/pixcomp.c +++ b/src/pixcomp.c @@ -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 diff --git a/src/pnmio.c b/src/pnmio.c index c3e2831c9..cb3a49cfd 100644 --- a/src/pnmio.c +++ b/src/pnmio.c @@ -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 @@ -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 diff --git a/src/ptabasic.c b/src/ptabasic.c index 3e9a0fe13..c4ea159f1 100644 --- a/src/ptabasic.c +++ b/src/ptabasic.c @@ -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 @@ -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 diff --git a/src/recogbasic.c b/src/recogbasic.c index a6a4b6b09..5290735d8 100644 --- a/src/recogbasic.c +++ b/src/recogbasic.c @@ -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 diff --git a/src/sarray1.c b/src/sarray1.c index ba5719a99..5436c063c 100644 --- a/src/sarray1.c +++ b/src/sarray1.c @@ -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 diff --git a/version-notes.html b/version-notes.html index 3701777e3..69143f2f0 100644 --- a/version-notes.html +++ b/version-notes.html @@ -108,12 +108,15 @@