aboutsummaryrefslogtreecommitdiff
path: root/lib/common
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-03-01 21:54:08 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-03-01 21:54:08 +0100
commit39bfcc7f27b5c5173455140abf902b38c21f0acb (patch)
tree876a6a2e757060343dfada7c2ed05f521fe2d969 /lib/common
parenteedb0793a2b2600c3bc213ddb869337fb09959de (diff)
Fix: Replace bit shifts in parse_size with SZ_MUL_OV
On 32 bit systems, size_t is a 32 bit integer and doing 64 bit shifts won't do us any good. So instead, use the existing size_t multiply and catch overflow macros. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/common')
-rw-r--r--lib/common/parse_size.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/lib/common/parse_size.c b/lib/common/parse_size.c
index 1285d3b..3e79a19 100644
--- a/lib/common/parse_size.c
+++ b/lib/common/parse_size.c
@@ -31,23 +31,20 @@ int parse_size(const char *what, size_t *out, const char *str,
switch (*in) {
case 'k':
case 'K':
- if (acc > ((1UL << (SIZEOF_SIZE_T * CHAR_BIT - 10)) - 1UL))
+ if (SZ_MUL_OV(acc, 1024, &acc))
goto fail_ov;
- acc <<= 10;
++in;
break;
case 'm':
case 'M':
- if (acc > ((1UL << (SIZEOF_SIZE_T * CHAR_BIT - 20)) - 1UL))
+ if (SZ_MUL_OV(acc, 1048576, &acc))
goto fail_ov;
- acc <<= 20;
++in;
break;
case 'g':
case 'G':
- if (acc > ((1UL << (SIZEOF_SIZE_T * CHAR_BIT - 30)) - 1UL))
+ if (SZ_MUL_OV(acc, 1073741824, &acc))
goto fail_ov;
- acc <<= 30;
++in;
break;
case '%':