Browse Source

[trac61] minor cleanup: delay variable declaration as much as possible,
also add a comment about why we need isdigit() check.

JINMEI Tatuya 14 years ago
parent
commit
5cfa9db0c1
1 changed files with 5 additions and 5 deletions
  1. 5 5
      src/lib/dns/dnssectime.cc

+ 5 - 5
src/lib/dns/dnssectime.cc

@@ -75,16 +75,16 @@ isLeap(const int y) {
 
 uint64_t
 timeFromText64(const string& time_txt) {
-    // first try reading YYYYMMDDHHmmSS format
-    int year, month, day, hour, minute, second;
-
+    // Confirm the source only consists digits.  sscanf() allows some
+    // minor exceptions.
     for (int i = 0; i < time_txt.length(); ++i) {
         if (!isdigit(time_txt.at(i))) {
-            isc_throw(InvalidTime,
-                      "Couldn't convert non-numeric time value: " << time_txt); 
+            isc_throw(InvalidTime, "Couldn't convert non-numeric time value: "
+                      << time_txt); 
         }
     }
 
+    int year, month, day, hour, minute, second;
     if (time_txt.length() != DATE_LEN ||
         sscanf(time_txt.c_str(), "%4d%2d%2d%2d%2d%2d",
                &year, &month, &day, &hour, &minute, &second) != 6)