|
16 | 16 | */
|
17 | 17 | #define MAX_LOCAL_LABELS 32
|
18 | 18 |
|
| 19 | +/* Local labels are encoded as 'L42', this requires 4 bytes of storage: |
| 20 | + * 3 characters + zero byte |
| 21 | + */ |
| 22 | +#define LOCAL_LABEL_LEN 4 |
| 23 | + |
19 | 24 | static bool llvm_initialized;
|
20 | 25 |
|
21 | 26 | struct local_labels {
|
22 | 27 | bool print_phase;
|
23 | 28 | __u32 prog_len;
|
24 | 29 | __u32 cnt;
|
25 | 30 | __u32 pcs[MAX_LOCAL_LABELS];
|
26 |
| - char names[MAX_LOCAL_LABELS][4]; |
| 31 | + char names[MAX_LOCAL_LABELS][LOCAL_LABEL_LEN]; |
27 | 32 | };
|
28 | 33 |
|
29 | 34 | static const char *lookup_symbol(void *data, uint64_t ref_value, uint64_t *ref_type,
|
@@ -118,8 +123,14 @@ static int disasm_one_func(FILE *text_out, uint8_t *image, __u32 len)
|
118 | 123 | }
|
119 | 124 | qsort(labels.pcs, labels.cnt, sizeof(*labels.pcs), cmp_u32);
|
120 | 125 | for (i = 0; i < labels.cnt; ++i)
|
121 |
| - /* use (i % 100) to avoid format truncation warning */ |
122 |
| - snprintf(labels.names[i], sizeof(labels.names[i]), "L%d", i % 100); |
| 126 | + /* gcc is unable to infer upper bound for labels.cnt and assumes |
| 127 | + * it to be U32_MAX. U32_MAX takes 10 decimal digits. |
| 128 | + * snprintf below prints into labels.names[*], |
| 129 | + * which has space only for two digits and a letter. |
| 130 | + * To avoid truncation warning use (i % MAX_LOCAL_LABELS), |
| 131 | + * which informs gcc about printed value upper bound. |
| 132 | + */ |
| 133 | + snprintf(labels.names[i], sizeof(labels.names[i]), "L%d", i % MAX_LOCAL_LABELS); |
123 | 134 |
|
124 | 135 | /* now print with labels */
|
125 | 136 | labels.print_phase = true;
|
|
0 commit comments