about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-03-23 16:19:04 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-03-23 16:19:04 +0000
commit2eae804b74e84addce536e9fd771fee07e24494c (patch)
tree0e11f81e18e54ef9c8be5e4ee12e0850008f9a72
parente274e29580c01b20e8ea14cefd9b57e5a12fecc4 (diff)
downloadnetpbm-mirror-2eae804b74e84addce536e9fd771fee07e24494c.tar.gz
netpbm-mirror-2eae804b74e84addce536e9fd771fee07e24494c.tar.xz
netpbm-mirror-2eae804b74e84addce536e9fd771fee07e24494c.zip
Don't crash on blank line in font file. Ignore blank line in font file
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1156 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--doc/HISTORY3
-rw-r--r--lib/libpbmfont.c35
2 files changed, 27 insertions, 11 deletions
diff --git a/doc/HISTORY b/doc/HISTORY
index d738272b..63d3545e 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -39,6 +39,9 @@ not yet  BJH  Release 10.50.00
               pbmpscale: speedup.
 
               pbmclean: speedup.
+
+              pbmtext: fix crash when BDF font file contains spurious
+              blank line.  Ignore such blank lines.
               
               pbmpscale: fix arithmetic overflow on output image dimensions.
 
diff --git a/lib/libpbmfont.c b/lib/libpbmfont.c
index a23abf9e..793de6c5 100644
--- a/lib/libpbmfont.c
+++ b/lib/libpbmfont.c
@@ -1106,20 +1106,28 @@ readline(FILE *        const ifP,
          char *        const line,
          const char ** const wordList) {
 /*----------------------------------------------------------------------------
-   Read a line from file *ifP.  Return the value of the whole line
+   Read a nonblank line from file *ifP.  Return the value of the whole line
    in *buf (must be at least 1024 bytes long), and parse it into words
    in *wordList (must have at least 32 entries).
+
+   If there is no nonblank line before EOF, return rc == -1.
 -----------------------------------------------------------------------------*/
-    int retval;
-    char * rc;
+    bool gotLine;
+    bool error;
 
-    rc = fgets(line, 1024, ifP);
-    if (rc == NULL)
-        retval = -1;
-    else
-        retval = mk_argvn(line, wordList, 32);
+    for (gotLine = false, error = false; !gotLine && !error; ) {
+        char * rc;
 
-    return retval;
+        rc = fgets(line, 1024, ifP);
+        if (rc == NULL)
+            error = true;
+        else {
+            mk_argvn(line, wordList, 32);
+            if (wordList[0] != NULL)
+                gotLine = true;
+        }
+    }
+    return error ? -1 : 0;
 }
 
 
@@ -1412,12 +1420,14 @@ processBdfFontLine(FILE *        const fp,
                    struct font * const fontP,
                    bool *        const endOfFontP) {
 /*----------------------------------------------------------------------------
-   Process a line just read from a BDF font file.
+   Process a nonblank line just read from a BDF font file.
 
    This processing may involve reading more lines.
 -----------------------------------------------------------------------------*/
     *endOfFontP = FALSE;  /* initial assumption */
 
+    assert(arg[0] != NULL);  /* Entry condition */
+
     if (streq(arg[0], "COMMENT")) {
         /* ignore */
     } else if (streq(arg[0], "SIZE")) {
@@ -1441,8 +1451,11 @@ processBdfFontLine(FILE *        const fp,
         fontP->y         = atoi(arg[4]);
     } else if (streq(arg[0], "ENDFONT")) {
         *endOfFontP = true;
-    } else if (streq(arg[0], "CHARS"))
+    } else if (streq(arg[0], "CHARS")) {
         processChars(fp, arg, fontP);
+    } else {
+        /* ignore */
+    }
 }