[exim-cvs] Support "G" modifier on numbers in ${if compariso…

Top Pagina
Delete this message
Reply to this message
Auteur: Exim Git Commits Mailing List
Datum:  
Aan: exim-cvs
Onderwerp: [exim-cvs] Support "G" modifier on numbers in ${if comparisons.
Gitweb: http://git.exim.org/exim.git/commitdiff/4eb9d6ef85652741d2852f89365a0af08ddc382e
Commit:     4eb9d6ef85652741d2852f89365a0af08ddc382e
Parent:     976b7e9fc18bab62d624acf49c6330915b875d41
Author:     Jeremy Harris <jgh146exb@???>
AuthorDate: Tue Jun 5 16:16:40 2012 +0100
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Tue Jun 5 16:16:40 2012 +0100


    Support "G" modifier on numbers in ${if comparisons.
---
 src/src/expand.c             |   27 +++++++++++++++++----------
 test/scripts/0000-Basic/0002 |    6 ++++++
 2 files changed, 23 insertions(+), 10 deletions(-)


diff --git a/src/src/expand.c b/src/src/expand.c
index 62e8e57..70bd86f 100644
--- a/src/src/expand.c
+++ b/src/src/expand.c
@@ -6217,18 +6217,25 @@ else if (value < 0 && isplus)
   }
 else
   {
-  if (tolower(*endptr) == 'k')
+  switch (tolower(*endptr))
     {
-    if (value > LLONG_MAX/1024 || value < LLONG_MIN/1024) errno = ERANGE;
+    default:
+      break;
+    case 'k':
+      if (value > LLONG_MAX/1024 || value < LLONG_MIN/1024) errno = ERANGE;
       else value *= 1024;
-    endptr++;
-    }
-    else if (tolower(*endptr) == 'm')
-    {
-    if (value > LLONG_MAX/(1024*1024) || value < LLONG_MIN/(1024*1024))
-      errno = ERANGE;
-    else value *= 1024*1024;
-    endptr++;
+      endptr++;
+      break;
+    case 'm':
+      if (value > LLONG_MAX/(1024*1024) || value < LLONG_MIN/(1024*1024)) errno = ERANGE;
+      else value *= 1024*1024;
+      endptr++;
+      break;
+    case 'g':
+      if (value > LLONG_MAX/(1024*1024*1024) || value < LLONG_MIN/(1024*1024*1024)) errno = ERANGE;
+      else value *= 1024*1024*1024;
+      endptr++;
+      break;
     }
   if (errno == ERANGE)
     msg = US"absolute value of integer \"%s\" is too large (overflow)";
diff --git a/test/scripts/0000-Basic/0002 b/test/scripts/0000-Basic/0002
index f87251e..40e4259 100644
--- a/test/scripts/0000-Basic/0002
+++ b/test/scripts/0000-Basic/0002
@@ -238,6 +238,12 @@ hash:   ${if eq {1}{2}{${hash_3:invalid}}{NO}}
 md5:    ${if eq {1}{2}{${md5:invalid}}{NO}}
 mask:   ${if eq {1}{2}{${mask:invalid}}{NO}}


+# Number suffixes in conditions
+1k: ${if >{1}{1k}{n}{y}}
+1K: ${if >{1}{1K}{n}{y}}
+1M: ${if >{1}{1M}{n}{y}}
+1G: ${if >{1}{1G}{n}{y}}
+
# Numeric overflow
# >32b should work, >64b not