From 7ed944254f4d5f91a48cdaab643d630e9f532af6 Mon Sep 17 00:00:00 2001 From: swirl Date: Tue, 14 Jun 2022 21:04:26 -0400 Subject: remove VLAs in OMEMO QR Code function Removes the use of VLAs in favor of calloc Signed-off-by: swirl --- src/ui/console.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 37b2d377..7f245a16 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -878,17 +878,21 @@ cons_show_qrcode(const char* const text) ProfWin* console = wins_get_console(); - char buf[(width * 4) + 1]; - memset(buf, 0, sizeof buf); + char *buf = calloc((width * 4) + 1, 1); - char tmp[(width * 4) + 5]; - memset(tmp, 0, sizeof tmp); + char *pad = calloc((width * 4) + 5, 1); + + if (!buf || !pad) { + free(pad); + free(buf); + return; + } for (int i = 0; i < width + 2 * ZOOM_SIZE; i += ZOOM_SIZE) { - strcat(tmp, "\u2588\u2588"); + strcat(pad, "\u2588\u2588"); } - win_println(console, THEME_DEFAULT, "", tmp); + win_println(console, THEME_DEFAULT, "", pad); for (size_t y = 0; y < width; y += ZOOM_SIZE) { for (size_t x = 0; x < width; x += ZOOM_SIZE) { strcat(buf, !(*data & 1) ? "\u2588\u2588" : "\u2800\u2800"); @@ -901,7 +905,10 @@ cons_show_qrcode(const char* const text) win_println(console, THEME_DEFAULT, "", "\u2588\u2588%s\u2588\u2588", buf); memset(buf, 0, sizeof buf); } - win_println(console, THEME_DEFAULT, "", "%s", tmp); + win_println(console, THEME_DEFAULT, "", "%s", pad); + + free(pad); + free(buf); QRcode_free(qrcode); #else @@ -2941,3 +2948,4 @@ cons_remove_alert(ProfWin* window) g_list_free_full(item, g_free); free(win_name); } + -- cgit 1.4.1-2-gfad0 From 7276db07f4dcee46b81506e4855bc01338455aea Mon Sep 17 00:00:00 2001 From: swirl Date: Wed, 15 Jun 2022 08:36:24 -0400 Subject: remove memset in cons_show_qrcode Signed-off-by: swirl --- src/ui/console.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/console.c b/src/ui/console.c index 7f245a16..960aa5ea 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -903,7 +903,7 @@ cons_show_qrcode(const char* const text) // The extra squares are for padding, so that the QR code doesn't // "blend in" with the rest of the terminal window. win_println(console, THEME_DEFAULT, "", "\u2588\u2588%s\u2588\u2588", buf); - memset(buf, 0, sizeof buf); + buf = { 0 }; } win_println(console, THEME_DEFAULT, "", "%s", pad); -- cgit 1.4.1-2-gfad0 From 35d10868f4a531eeb2dad8ae5bc3feb9f090b09e Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 15 Jun 2022 14:53:08 +0200 Subject: Reset buffer correctly --- src/ui/console.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 960aa5ea..6698a503 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -878,9 +878,8 @@ cons_show_qrcode(const char* const text) ProfWin* console = wins_get_console(); - char *buf = calloc((width * 4) + 1, 1); - - char *pad = calloc((width * 4) + 5, 1); + char* buf = calloc((width * 4) + 1, 1); + char* pad = calloc((width * 4) + 5, 1); if (!buf || !pad) { free(pad); @@ -903,7 +902,7 @@ cons_show_qrcode(const char* const text) // The extra squares are for padding, so that the QR code doesn't // "blend in" with the rest of the terminal window. win_println(console, THEME_DEFAULT, "", "\u2588\u2588%s\u2588\u2588", buf); - buf = { 0 }; + buf[0] = '\0'; } win_println(console, THEME_DEFAULT, "", "%s", pad); @@ -2948,4 +2947,3 @@ cons_remove_alert(ProfWin* window) g_list_free_full(item, g_free); free(win_name); } - -- cgit 1.4.1-2-gfad0