Skip to content

Commit 97aefe3

Browse files
authored
Merge pull request #26 from caternuson/iss25
Add except to catch small int overflow
2 parents c22eca9 + 8a4236f commit 97aefe3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

adafruit_framebuf.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,17 @@ def __init__(self, font_name='font5x8.bin'):
396396
# Note that only fonts up to 8 pixels tall are currently supported.
397397
try:
398398
self._font = open(self.font_name, 'rb')
399+
self.font_width, self.font_height = struct.unpack('BB', self._font.read(2))
400+
# simple font file validation check based on expected file size
401+
if 2 + 256 * self.font_width != os.stat(font_name)[6]:
402+
raise RuntimeError("Invalid font file: " + font_name)
399403
except OSError:
400404
print("Could not find font file", font_name)
401405
raise
402-
self.font_width, self.font_height = struct.unpack('BB', self._font.read(2))
403-
# simple font file validation check based on expected file size
404-
if 2 + 256 * self.font_width != os.stat(font_name)[6]:
405-
raise RuntimeError("Invalid font file: " + font_name)
406+
except OverflowError:
407+
# os.stat can throw this on boards without long int support
408+
# just hope the font file is valid and press on
409+
pass
406410

407411
def deinit(self):
408412
"""Close the font file as cleanup."""

0 commit comments

Comments
 (0)