]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
minor : factor out errorOut()
authorYann Collet <cyan@fb.com>
Sat, 12 May 2018 19:34:34 +0000 (12:34 -0700)
committerYann Collet <cyan@fb.com>
Sat, 12 May 2018 21:09:32 +0000 (14:09 -0700)
tests/paramgrill.c

index 984fb308fd3025130b1d4bb54ca9b920193692e0..7e4c6b75f01db989555c664d9380391e32e1fa01 100644 (file)
@@ -886,6 +886,11 @@ int optimizeForSize(const char* inFileName, U32 targetSpeed)
     return 0;
 }
 
+static void errorOut(const char* msg)
+{
+    DISPLAY("%s \n", msg); exit(1);
+}
+
 /*! readU32FromChar() :
  * @return : unsigned integer value read from input in `char` format.
  *  allows and interprets K, KB, KiB, M, MB and MiB suffix.
@@ -893,23 +898,19 @@ int optimizeForSize(const char* inFileName, U32 targetSpeed)
  *  Note : function will exit() program if digit sequence overflows */
 static unsigned readU32FromChar(const char** stringPtr)
 {
+    const char errorMsg[] = "error: numeric value too large";
     unsigned result = 0;
     while ((**stringPtr >='0') && (**stringPtr <='9')) {
         unsigned const max = (((unsigned)(-1)) / 10) - 1;
-        if (result > max) {
-            DISPLAY("error: numeric value too large \n");
-            exit(1);
-        }
+        if (result > max) errorOut(errorMsg);
         result *= 10, result += **stringPtr - '0', (*stringPtr)++ ;
     }
     if ((**stringPtr=='K') || (**stringPtr=='M')) {
         unsigned const maxK = ((unsigned)(-1)) >> 10;
+        if (result > maxK) errorOut(errorMsg);
         result <<= 10;
         if (**stringPtr=='M') {
-            if (result > maxK) {
-                DISPLAY("error: numeric value too large \n");
-                exit(1);
-            }
+            if (result > maxK) errorOut(errorMsg);
             result <<= 10;
         }
         (*stringPtr)++;  /* skip `K` or `M` */