diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2010-06-12 22:02:21 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2010-06-12 22:02:21 +0000 |
commit | be1ba93b7e2877073b61f75b29a3170f7c862384 (patch) | |
tree | 5e61986f458403132c8c55bd16ab10be0e59b723 | |
parent | bd23575af14b8e1245789aaa726b0212802db871 (diff) | |
download | netpbm-mirror-be1ba93b7e2877073b61f75b29a3170f7c862384.tar.gz netpbm-mirror-be1ba93b7e2877073b61f75b29a3170f7c862384.tar.xz netpbm-mirror-be1ba93b7e2877073b61f75b29a3170f7c862384.zip |
Fix error message where hex string ends prematurely
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1237 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r-- | lib/libpbmfont.c | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/lib/libpbmfont.c b/lib/libpbmfont.c index 793de6c5..eef915c1 100644 --- a/lib/libpbmfont.c +++ b/lib/libpbmfont.c @@ -1159,28 +1159,34 @@ readBitmap(FILE * const fp, hex = line; for (i = glyphWidth; i > 0; i -= 4) { - char hdig; - unsigned int hdigValue; - hdig = *hex++; - if (hdig >= '0' && hdig <= '9') - hdigValue = hdig - '0'; - else if (hdig >= 'a' && hdig <= 'f') - hdigValue = 10 + (hdig - 'a'); - else if (hdig >= 'A' && hdig <= 'F') - hdigValue = 10 + (hdig - 'A'); - else - pm_error("Invalid hex digit '%c' in line '%s' of " + if (*hex == '\0') + pm_error("Premature end of line in line '%s' of " "bitmap for character '%s' " - "in BDF font file", hdig, line, charName); + "in BDF font file", line, charName); + else { + char const hdig = *hex++; + unsigned int hdigValue; + + if (hdig >= '0' && hdig <= '9') + hdigValue = hdig - '0'; + else if (hdig >= 'a' && hdig <= 'f') + hdigValue = 10 + (hdig - 'a'); + else if (hdig >= 'A' && hdig <= 'F') + hdigValue = 10 + (hdig - 'A'); + else + pm_error("Invalid hex digit '%c' in line '%s' of " + "bitmap for character '%s' " + "in BDF font file", hdig, line, charName); - if (i > 0) - bmap[bmapIndex++] = hdigValue & 0x8 ? 1 : 0; - if (i > 1) - bmap[bmapIndex++] = hdigValue & 0x4 ? 1 : 0; - if (i > 2) - bmap[bmapIndex++] = hdigValue & 0x2 ? 1 : 0; - if (i > 3) - bmap[bmapIndex++] = hdigValue & 0x1 ? 1 : 0; + if (i > 0) + bmap[bmapIndex++] = hdigValue & 0x8 ? 1 : 0; + if (i > 1) + bmap[bmapIndex++] = hdigValue & 0x4 ? 1 : 0; + if (i > 2) + bmap[bmapIndex++] = hdigValue & 0x2 ? 1 : 0; + if (i > 3) + bmap[bmapIndex++] = hdigValue & 0x1 ? 1 : 0; + } } } } |