From b5e4b589024a537b8ff8099bd6ea4499e8d5296f Mon Sep 17 00:00:00 2001 From: nick black Date: Tue, 26 Oct 2021 15:22:21 -0400 Subject: [PATCH] [linux] eliminate VLAs --- src/lib/linux.c | 6 ++++-- src/poc/linuxconsole.c | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lib/linux.c b/src/lib/linux.c index 1d85ae18b..d2a6eaa96 100644 --- a/src/lib/linux.c +++ b/src/lib/linux.c @@ -364,8 +364,9 @@ program_line_drawing_chars(int fd, struct unimapdesc* map){ for(size_t sidx = 0 ; sidx < sizeof(sets) / sizeof(*sets) ; ++sidx){ int fontidx = -1; struct simset* s = &sets[sidx]; - bool found[wcslen(s->ws)]; - memset(found, 0, sizeof(found)); + size_t fsize = sizeof(bool) * wcslen(s->ws); + bool* found = malloc(fsize); + memset(found, 0, fsize); for(unsigned idx = 0 ; idx < map->entry_ct ; ++idx){ for(size_t widx = 0 ; widx < wcslen(s->ws) ; ++widx){ if(map->entries[idx].unicode == s->ws[widx]){ @@ -390,6 +391,7 @@ program_line_drawing_chars(int fd, struct unimapdesc* map){ }else{ logwarn("Couldn't find any glyphs for set %zu\n", sidx); } + free(found); } if(toadd == 0){ return 0; diff --git a/src/poc/linuxconsole.c b/src/poc/linuxconsole.c index 7cc44c42c..4661c51e4 100644 --- a/src/poc/linuxconsole.c +++ b/src/poc/linuxconsole.c @@ -69,7 +69,7 @@ get_linux_colormap(int fd){ // // height * rowbytes, where rowbytes = width + 7 / 8 static int -explode_glyph_row(const unsigned char** row, unsigned width){ +explode_glyph_row(unsigned char** row, unsigned width){ unsigned char mask = 0x80; while(width--){ printf("%s", **row & mask ? "*" : " "); @@ -110,7 +110,7 @@ get_linux_consolefont(int fd, unsigned showglyphs){ // FIXME get real screen width const int atonce = 80 / (cfo.width + 1); const int Bper = 64; - const unsigned char* g[atonce]; + unsigned char** g = malloc(sizeof(*g) * atonce); for(unsigned i = 0 ; i < cfo.charcount ; i += atonce){ for(int o = 0 ; o < atonce ; ++o){ g[o] = (unsigned char*)cfo.data + Bper * (i + o); @@ -122,6 +122,7 @@ get_linux_consolefont(int fd, unsigned showglyphs){ printf("\n"); } } + free(g); } free(cfo.data); return 0;