Skip to content

Commit 242b832

Browse files
author
Keith Busch
committed
Use fixed-width integer types for long suffixed parameters
Fixes possible truncation on 32-bit archs. Link: linux-nvme/nvme-cli#330 Signed-off-by: Keith Busch <[email protected]>
1 parent 27e0db7 commit 242b832

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

argconfig.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ int argconfig_parse(int argc, char *argv[], const char *program_desc,
285285
goto out;
286286
}
287287
} else if (s->config_type == CFG_LONG_SUFFIX) {
288-
*((long *)value_addr) = suffix_binary_parse(optarg);
288+
*((uint64_t *)value_addr) = suffix_binary_parse(optarg);
289289
if (errno) {
290290
fprintf(stderr,
291291
"Expected long suffixed integer argument for '%s' but got '%s'!\n",

suffix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ const char *suffix_dbinary_get(double *value)
109109
return "";
110110
}
111111

112-
long long suffix_binary_parse(const char *value)
112+
uint64_t suffix_binary_parse(const char *value)
113113
{
114114
char *suffix;
115115
errno = 0;
116-
long long ret = strtoll(value, &suffix, 0);
116+
uint64_t ret = strtoll(value, &suffix, 0);
117117
if (errno)
118118
return 0;
119119

suffix.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131

3232
#ifndef __ARGCONFIG_SUFFIX_H__
3333

34+
#include <inttypes.h>
35+
3436
const char *suffix_si_get(double *value);
3537
const char *suffix_binary_get(long long *value);
3638
const char *suffix_dbinary_get(double *value);
37-
long long suffix_binary_parse(const char *value);
39+
uint64_t suffix_binary_parse(const char *value);
3840

3941
#endif

0 commit comments

Comments
 (0)