Skip to content

Commit f0fe17d

Browse files
shiqingglijinxia
authored andcommitted
hv: sprintf: fix 'Declaration does not specify an array'
The array size of upper_hex_digits and lower_hex_digits are same and constant. Use an array rather than a pointer to fix the violation - 'Declaration does not specify an array' v3 -> v4: * Update the array size of 'digits' * Update the usage of 'digits' v2 -> v3: * Update the usage of 'digits' v1 -> v2: * Define a MACRO for the array size of 'digits' * Simplify the declaration of 'digits' Signed-off-by: Shiqing Gao <shiqing.gao@intel.com> Reviewed-by: Junjie Mao <junjie.mao@intel.com>
1 parent aa5027a commit f0fe17d

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

hypervisor/lib/sprintf.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#define NULL ((void *) 0)
1111
#endif
1212

13-
#define PRINT_STRING_MAX_LEN 4096
13+
#define PRINT_STRING_MAX_LEN 4096U
14+
15+
#define HEX_DIGITS_LEN 17U
1416

1517
/** Use upper case letters for hexadecimal format. */
1618
#define PRINT_FLAG_UPPER 0x00000001U
@@ -292,7 +294,7 @@ static int print_pow2(struct print_param *param,
292294
/* buffer for the 0/0x/0X prefix */
293295
char prefix[2];
294296
/* pointer to the digits translation table */
295-
const char *digits;
297+
const char (*digits)[HEX_DIGITS_LEN];
296298
/* mask to extract next character */
297299
uint64_t mask;
298300
int ret;
@@ -302,7 +304,7 @@ static int print_pow2(struct print_param *param,
302304

303305
/* determine digit translation table */
304306
digits = ((param->vars.flags & PRINT_FLAG_UPPER) != 0) ?
305-
upper_hex_digits : lower_hex_digits;
307+
&upper_hex_digits : &lower_hex_digits;
306308

307309
/* apply mask for short/char */
308310
v &= param->vars.mask;
@@ -315,14 +317,14 @@ static int print_pow2(struct print_param *param,
315317

316318
if (shift == 4U) {
317319
param->vars.prefixlen = 2U;
318-
prefix[1] = digits[16];
320+
prefix[1] = (*digits)[16];
319321
}
320322
}
321323

322324
/* determine digits from right to left */
323325
do {
324326
pos--;
325-
*pos = digits[(v & mask)];
327+
*pos = (*digits)[(v & mask)];
326328
v >>= shift;
327329
} while (v != 0UL);
328330

0 commit comments

Comments
 (0)