about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2022-06-15 15:22:15 +0200
committerGitHub <noreply@github.com>2022-06-15 15:22:15 +0200
commite05e37f7b01453eb2ba5d642179273b7c1eb0423 (patch)
tree570a81b08c3f1f9f74348cefecfc3197854a84a2
parent4d6bc1adf8301dc5dc1986cc868171e2dd9179e1 (diff)
parent35d10868f4a531eeb2dad8ae5bc3feb9f090b09e (diff)
downloadprofani-tty-e05e37f7b01453eb2ba5d642179273b7c1eb0423.tar.gz
Merge pull request #1720 from binex-dsk/removal/omemo-qrcode-vla
remove VLAs in OMEMO QR Code function
-rw-r--r--src/ui/console.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/ui/console.c b/src/ui/console.c
index 37b2d377..6698a503 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -878,17 +878,20 @@ 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* pad = calloc((width * 4) + 5, 1);
 
-    char tmp[(width * 4) + 5];
-    memset(tmp, 0, sizeof tmp);
+    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");
@@ -899,9 +902,12 @@ 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] = '\0';
     }
-    win_println(console, THEME_DEFAULT, "", "%s", tmp);
+    win_println(console, THEME_DEFAULT, "", "%s", pad);
+
+    free(pad);
+    free(buf);
 
     QRcode_free(qrcode);
 #else