aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakayuki Matsuoka <t-mat@users.noreply.github.com>2022-08-13 00:25:13 +0900
committerTakayuki Matsuoka <t-mat@users.noreply.github.com>2022-08-13 00:25:13 +0900
commitf892f828838c064dab8d754388506c94e37c3fe1 (patch)
tree4d4608baea8002ee2e557e24d417782fa3bf61ff
parentaf0d7c0cb811e83a89d0ded3ba3bdea1895a2f8a (diff)
downloadlz4-f892f828838c064dab8d754388506c94e37c3fe1.tar.gz
Suppress false positive warning from MSVC (datagencli.c)
MSVC 2022 reports the follwing false positve warnings: lz4\tests\datagencli.c(110): warning C26451: Arithmetic overflow: Using operator '-' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '-' to avoid overflow (io.2). lz4\tests\datagencli.c(134): warning C26451: Arithmetic overflow: Using operator '-' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '-' to avoid overflow (io.2). lz4\tests\datagencli.c(146): warning C26451: Arithmetic overflow: Using operator '-' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '-' to avoid overflow (io.2). Although they're absolutely compiler's and static analyzer's bug, it'd always be nice to use the standard library.
-rw-r--r--tests/datagencli.c32
1 files changed, 4 insertions, 28 deletions
diff --git a/tests/datagencli.c b/tests/datagencli.c
index 9efe27e1..1a99190e 100644
--- a/tests/datagencli.c
+++ b/tests/datagencli.c
@@ -104,12 +104,7 @@ int main(int argc, char** argv)
case 'g':
argument++;
size=0;
- while ((*argument>='0') && (*argument<='9'))
- {
- size *= 10;
- size += *argument - '0';
- argument++;
- }
+ size = strtoull(argument, &argument, 10);
if (*argument=='K') { size <<= 10; argument++; }
if (*argument=='M') { size <<= 20; argument++; }
if (*argument=='G') { size <<= 30; argument++; }
@@ -117,35 +112,16 @@ int main(int argc, char** argv)
break;
case 's':
argument++;
- seed=0;
- while ((*argument>='0') && (*argument<='9'))
- {
- seed *= 10;
- seed += *argument - '0';
- argument++;
- }
+ seed = (U32) strtoul(argument, &argument, 10);
break;
case 'P':
argument++;
- proba=0.0;
- while ((*argument>='0') && (*argument<='9'))
- {
- proba *= 10;
- proba += *argument - '0';
- argument++;
- }
- if (proba>100.) proba=100.;
+ proba = (double) strtoull(argument, &argument, 10);
proba /= 100.;
break;
case 'L': /* hidden argument : Literal distribution probability */
argument++;
- litProba=0.;
- while ((*argument>='0') && (*argument<='9'))
- {
- litProba *= 10;
- litProba += *argument - '0';
- argument++;
- }
+ litProba = (double) strtoull(argument, &argument, 10);
if (litProba>100.) litProba=100.;
litProba /= 100.;
break;