summaryrefslogtreecommitdiff
path: root/sys/src/libdraw/font.c
AgeCommit message (Collapse)Author
2016-04-13libdraw: avoid BPSHORT()/BPLONG() expansion, cleanup loadchar(),cachechars()cinap_lenrek
assigning the expression value to a temporary variable in BPSHORT() and BPLONG() saves arround 2K of text in rio on arm and arround 1K on amd64. loadchar(): use the passed in "h" as the char index instead of recomputing it from c-f->cache. dont recompute wid. cachechars(): do cache lookup and find oldest entry in a single loop pass.
2016-04-05libdraw: fix out of bounds memory access after subfont array reallocation ↵cinap_lenrek
(thanks ray) /n/bugs/open/libdrawfont.c_buffer_overflow http://bugs.9front.org/open/libdrawfont.c_buffer_overflow/readme ray@raylai.com Hi all, In plan9port this bug keeps crashing mc when I run lc in a directory with Chinese characters. This is a diff from OpenBSD but it should apply cleanly to the various plan9 sources. The code is basically trying to do a realloc (I guess realloc wasn't available back then?) but it copies too much from the original buffer. Since realloc is available, just use it. If realloc isn't available outside plan9port (I haven't checked) the memmove line should be changed from: memmove(f->subf, of, (f->nsubf+DSUBF)*sizeof *subf); to: memmove(f->subf, of, f->nsubf*sizeof *subf); I hope this is helpful. Ray
2016-03-12libdraw: remove flushimage calls from fontresize() and loadchar()cinap_lenrek
2015-06-09libdraw: consistent use of nil for pointers, error handlingcinap_lenrek
2015-03-02libdraw: font->display->defaultsubfont vs. display->defaultsubfont, dead ↵cinap_lenrek
code, malloc erros it is possible to have fonts belong to different or no display, so the check for defaultsubfont has to be against font->display, not the global display variable. remove unused freeup() routine. handle strdup() error in allocsubfont() and realloc() error in buildfont().
2014-03-10libdraw: fix zero stringwidth() bugcinap_lenrek
stringwidth() and string() sometimes failed spuriously due to the wrong assumption that cachechars() will only fail when a different subfont is needed. in fact, cachechars() can fail for other reasons like when it resizes the fontcache (or fails todo so). theres also the case when loadchar() is unable to translate a character and returns 0. this case needs to be differentiated from such temporary conditions like fontcache resize or subfont load to stop the retry loop in string() and stringwidth(). now cachechars() returns -1 to indicate that it cannot proceed and we test this in string() and stringwidth() to skip over untranslatable characters to make progress instead of retrying.
2014-01-06libdraw: fix stringwidth problemscinap_lenrek
cachechars() used to skip over characters on its own when loadchar() could not find the character or a PJW replacement. this resulted in wrong width calculation. now we just return and handle the case inside _string and _stringwidth. fix subfont leak in stringwidth() remove annoying prints in stringwidth()
2013-05-25libdraw: fix agefont crash when display == nil (from sources / ↵cinap_lenrek
agefont-nodisplay patch) If you run this: {for (i in `{seq 1 70000}) echo '½•α·'} | mc | wc mc will eventually suicide. The error comes from /sys/src/libdraw/font.c:/^agefont which assumes it has a display. Normally, this is set up by geninitdraw (usually via initdraw), but mc.c avoids that to avoid the screen redraws (flicker, at a minimum, but worse in long-running cases). graphics(2) does not prohibit this use, so I made the least intrusive change to make it work.
2013-05-04libdraw: fix font f->cacheimage nil dereferencecinap_lenrek
the initial fontresize() might fail but its error code is ignored potentially leaving f->cacheimage == nil. make sure we call fontresize() in loadchar() when theres no cacheimage and check the return value to avoid nil pointer dereference.
2011-11-10libdraw: dont abort() on failed allocimage in fontresize()cinap_lenrek
2011-03-30Import sources from 2011-03-30 iso image - libTaru Karttunen
2011-03-30Import sources from 2011-03-30 iso imageTaru Karttunen