Browse Source

[2384] Simplify range check

It doesn't need to check the number of digits. It seems the tests pass
now without problems as well. Also, it might be problematic with large
number of leading zeroes.

Also, simplify comment with description.
Michal 'vorner' Vaner 12 years ago
parent
commit
46f83b6608
1 changed files with 4 additions and 8 deletions
  1. 4 8
      src/lib/dns/rrttl.cc

+ 4 - 8
src/lib/dns/rrttl.cc

@@ -98,14 +98,10 @@ RRTTL::RRTTL(const std::string& ttlstr) {
                                                                       unit));
             // Add what we found
             val += multiply * value;
-            // The partial value is still in range (the value can only grow,
-            // so if we get out now, it won't get better).
-            //
-            // Any valid uint32_t number must have at most 10 digits. If it
-            // has more, it could wrap around the int64_t silently (at least
-            // in theory, some compilers seem to throw from lexical_cast).
-            if (unit - pos > 10 || value < 0 || val < 0 ||
-                val > 0xffffffff) {
+            // Check the partial value is still in range (the value can only
+            // grow, so if we get out of range now, it won't get better, so
+            // there's no need to continue).
+            if (value < 0 || val < 0 || val > 0xffffffff) {
                 isc_throw(InvalidRRTTL, "Part of TTL out of range: " <<
                           ttlstr);
             }