From 06be827457d2224dec04de406d7c2df6130eacc6 Mon Sep 17 00:00:00 2001 From: danblooomberg Date: Mon, 29 Jan 2024 19:24:48 -0800 Subject: [PATCH] Fix fscanf return value in recogReadStream() when it just reads a string. * No conversions were done; look for -1 error code for failure to read * Also, remove width table for bmf characters; it is not used. --- src/bmf.c | 18 ++---------------- src/bmf.h | 1 - src/recogbasic.c | 4 ++-- 3 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/bmf.c b/src/bmf.c index f03889a96..a53c2ce38 100644 --- a/src/bmf.c +++ b/src/bmf.c @@ -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; } @@ -761,16 +760,13 @@ NUMA *na; * *
  * 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)
@@ -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)
@@ -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);
diff --git a/src/bmf.h b/src/bmf.h
index 328e2c0d6..ea0339f6c 100644
--- a/src/bmf.h
+++ b/src/bmf.h
@@ -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;
 
diff --git a/src/recogbasic.c b/src/recogbasic.c
index 4d42468bf..a6a4b6b09 100644
--- a/src/recogbasic.c
+++ b/src/recogbasic.c
@@ -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);
     }
@@ -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);
     }