mirror of
https://github.com/adafruit/Adafruit-GFX-Library.git
synced 2026-10-27 06:21:36 +00:00
Preserve wide custom-font ranges on big-endian targets
GFXfont stores first and last as uint16_t, but the custom-font paths read them as bytes. Use word-width reads while retaining the existing 8-bit character API, so the stored range is interpreted correctly without changing the font format or adding UTF-8 behavior. Constraint: Keep the public 8-bit character API and limit the patch to issue #490\nRejected: UTF-8/API refactor | broader scope is outside the reported portability bug\nConfidence: high\nScope-risk: narrow\nReversibility: clean\nDirective: Keep GFXfont first/last accesses word-width when reading the stored range\nTested: MinGW GCC 8 -Wall -Wextra -Werror with an endian-aware host fixture; WSL GCC AddressSanitizer and UBSan; baseline fixture fails with 0x0 bounds while the fix passes with 5x7\nNot-tested: Physical Arduino board hardware
This commit is contained in:
1 parent
ac6d7c3869
commit
43e293c138
1 file changed
+5
-5
+5
-5
@@ -1435,7 +1435,7 @@ void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c,
|
||||
// newlines, returns, non-printable characters, etc. Calling
|
||||
// drawChar() directly with 'bad' characters of font may cause mayhem!
|
||||
|
||||
c -= (uint8_t)pgm_read_byte(&gfxFont->first);
|
||||
c -= (uint8_t)pgm_read_word(&gfxFont->first);
|
||||
GFXglyph *glyph = pgm_read_glyph_ptr(gfxFont, c);
|
||||
uint8_t *bitmap = pgm_read_bitmap_ptr(gfxFont);
|
||||
|
||||
@@ -1519,8 +1519,8 @@ size_t Adafruit_GFX::write(uint8_t c) {
|
||||
cursor_y +=
|
||||
(int16_t)textsize_y * (uint8_t)pgm_read_byte(&gfxFont->yAdvance);
|
||||
} else if (c != '\r') {
|
||||
uint8_t first = pgm_read_byte(&gfxFont->first);
|
||||
if ((c >= first) && (c <= (uint8_t)pgm_read_byte(&gfxFont->last))) {
|
||||
uint16_t first = pgm_read_word(&gfxFont->first);
|
||||
if ((c >= first) && (c <= pgm_read_word(&gfxFont->last))) {
|
||||
GFXglyph *glyph = pgm_read_glyph_ptr(gfxFont, c - first);
|
||||
uint8_t w = pgm_read_byte(&glyph->width),
|
||||
h = pgm_read_byte(&glyph->height);
|
||||
@@ -1635,8 +1635,8 @@ void Adafruit_GFX::charBounds(unsigned char c, int16_t *x, int16_t *y,
|
||||
*x = 0; // Reset x to zero, advance y by one line
|
||||
*y += textsize_y * (uint8_t)pgm_read_byte(&gfxFont->yAdvance);
|
||||
} else if (c != '\r') { // Not a carriage return; is normal char
|
||||
uint8_t first = pgm_read_byte(&gfxFont->first),
|
||||
last = pgm_read_byte(&gfxFont->last);
|
||||
uint16_t first = pgm_read_word(&gfxFont->first),
|
||||
last = pgm_read_word(&gfxFont->last);
|
||||
if ((c >= first) && (c <= last)) { // Char present in this font?
|
||||
GFXglyph *glyph = pgm_read_glyph_ptr(gfxFont, c - first);
|
||||
uint8_t gw = pgm_read_byte(&glyph->width),
|
||||
|
||||
Reference in new issue
Block a user