]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
Avoid using arrays with a variable length
authorBart Van Assche <bvanassche@acm.org>
Tue, 18 Jun 2019 20:16:56 +0000 (13:16 -0700)
committerBart Van Assche <bvanassche@acm.org>
Wed, 19 Jun 2019 16:17:14 +0000 (09:17 -0700)
Since variable length arrays result in suboptimal code, avoid using
variable length arrays.

Cc: Patrick McCormick <patrick.m.mccormick@intel.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
nvme-print.c

index ea8f720748ef02a0970b35a5e6579748168b6e9f..94222a3b1c15ee16806a0b726961628a5c7fbe37 100644 (file)
@@ -1,3 +1,4 @@
+#include <assert.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -41,8 +42,9 @@ static long double int128_to_double(__u8 *data)
 void d(unsigned char *buf, int len, int width, int group)
 {
        int i, offset = 0, line_done = 0;
-       char ascii[width + 1];
+       char ascii[32 + 1];
 
+       assert(width < sizeof(ascii));
        printf("     ");
        for (i = 0; i <= 15; i++)
                printf("%3x", i);