Skip to content

Commit

Permalink
Fix fscanf return value in recogReadStream() when it just reads a str…
Browse files Browse the repository at this point in the history
…ing.

* No conversions were done; look for -1 error code for failure to read
* Also, remove width table for bmf characters; it is not used.
  • Loading branch information
DanBloomberg committed Jan 30, 2024
1 parent f86cdab commit 06be827
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 19 deletions.
18 changes: 2 additions & 16 deletions src/bmf.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ L_BMF *bmf;
LEPT_FREE(bmf->directory);
LEPT_FREE(bmf->fonttab);
LEPT_FREE(bmf->baselinetab);
LEPT_FREE(bmf->widthtab);
LEPT_FREE(bmf);
*pbmf = NULL;
}
Expand Down Expand Up @@ -761,16 +760,13 @@ NUMA *na;
*
* <pre>
* Notes:
* (1) This makes three tables, each of size 128, as follows:
* (1) This makes two tables, each of size 128, as follows:
* ~ fonttab is a table containing the index of the Pix
* that corresponds to each input ascii character;
* it maps (ascii-index) --> Pixa index
* ~ baselinetab is a table containing the baseline offset
* for the Pix that corresponds to each input ascii character;
* it maps (ascii-index) --> baseline offset
* ~ widthtab is a table containing the character width in
* pixels for the Pix that corresponds to that character;
* it maps (ascii-index) --> bitmap width
* (2) This also computes
* ~ lineheight (sum of maximum character extensions above and
* below the baseline)
Expand All @@ -789,7 +785,7 @@ static l_int32
bmfMakeAsciiTables(L_BMF *bmf)
{
l_int32 i, maxh, height, charwidth, xwidth, kernwidth;
l_int32 *fonttab, *baselinetab, *widthtab;
l_int32 *fonttab, *baselinetab;
PIX *pix;

if (!bmf)
Expand All @@ -815,16 +811,6 @@ PIX *pix;
for (i = 93; i < 127; i++)
baselinetab[i] = bmf->baseline3;

/* Generate array of character widths; req's fonttab to exist */
widthtab = (l_int32 *)LEPT_CALLOC(128, sizeof(l_int32));
bmf->widthtab = widthtab;
for (i = 0; i < 128; i++)
widthtab[i] = UNDEF;
for (i = 32; i < 127; i++) {
bmfGetWidth(bmf, i, &charwidth);
widthtab[i] = charwidth;
}

/* Get the line height of text characters, from the highest
* ascender to the lowest descender; req's fonttab to exist. */
pix = bmfGetPix(bmf, 32);
Expand Down
1 change: 0 additions & 1 deletion src/bmf.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ struct L_Bmf
l_int32 vertlinesep; /*!< extra vertical space between text lines */
l_int32 *fonttab; /*!< table mapping ascii --> font index */
l_int32 *baselinetab; /*!< table mapping ascii --> baseline offset */
l_int32 *widthtab; /*!< table mapping ascii --> char width */
};
typedef struct L_Bmf L_BMF;

Expand Down
4 changes: 2 additions & 2 deletions src/recogbasic.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ SARRAY *sa_text;
maxyshift)) == NULL)
return (L_RECOG *)ERROR_PTR("recog not made", __func__, NULL);

if (fscanf(fp, "\nLabels for character set:\n") != 0) {
if (fscanf(fp, "\nLabels for character set:\n") == -1) {
recogDestroy(&recog);
return (L_RECOG *)ERROR_PTR("label intro not read", __func__, NULL);
}
Expand All @@ -894,7 +894,7 @@ SARRAY *sa_text;
}
recog->sa_text = sa_text;

if (fscanf(fp, "\nPixaa of all samples in the training set:\n") != 0) {
if (fscanf(fp, "\nPixaa of all samples in the training set:\n") == -1) {
recogDestroy(&recog);
return (L_RECOG *)ERROR_PTR("pixaa intro not read", __func__, NULL);
}
Expand Down

0 comments on commit 06be827

Please sign in to comment.