diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2021-07-06 16:06:23 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2021-07-06 16:06:23 +0200 |
commit | 4cebad3859f8cc4fe526a89ef2277d1db9ee9b7c (patch) | |
tree | 980ef15cfa6d2742f28afcbeaaf528d9f3637353 | |
parent | 739c96fc8e0dd5e9889149ece229c5300f3a58fb (diff) |
Clear errno before calling strto*() functions
-rw-r--r-- | libbutl/builtin.cxx | 1 | ||||
-rw-r--r-- | libbutl/semantic-version.cxx | 1 | ||||
-rw-r--r-- | libbutl/standard-version.cxx | 1 | ||||
-rw-r--r-- | tests/builtin/driver.cxx | 1 | ||||
-rw-r--r-- | tests/process-term/driver.cxx | 1 |
5 files changed, 4 insertions, 1 deletions
diff --git a/libbutl/builtin.cxx b/libbutl/builtin.cxx index a6bb94b..61df568 100644 --- a/libbutl/builtin.cxx +++ b/libbutl/builtin.cxx @@ -1929,6 +1929,7 @@ namespace butl if (!a.empty () && a[0] != '-' && a[0] != '+') { char* e (nullptr); + errno = 0; // We must clear it according to POSIX. n = strtoull (a.c_str (), &e, 10); // Can't throw. if (errno != ERANGE && e == a.c_str () + a.size ()) diff --git a/libbutl/semantic-version.cxx b/libbutl/semantic-version.cxx index eaf709d..445890d 100644 --- a/libbutl/semantic-version.cxx +++ b/libbutl/semantic-version.cxx @@ -14,7 +14,6 @@ #include <ostream> #include <cstring> // strchr() -#include <cstdlib> // strtoull() #include <utility> // move() #include <stdexcept> // invalid_argument #endif diff --git a/libbutl/standard-version.cxx b/libbutl/standard-version.cxx index a9f5eb8..863cb29 100644 --- a/libbutl/standard-version.cxx +++ b/libbutl/standard-version.cxx @@ -60,6 +60,7 @@ namespace butl const char* b (s.c_str () + p); char* e (nullptr); + errno = 0; // We must clear it according to POSIX. uint64_t v (strtoull (b, &e, 10)); // Can't throw. if (errno == ERANGE || b == e || v < min || v > max) diff --git a/tests/builtin/driver.cxx b/tests/builtin/driver.cxx index 843631a..bab74aa 100644 --- a/tests/builtin/driver.cxx +++ b/tests/builtin/driver.cxx @@ -90,6 +90,7 @@ main (int argc, char* argv[]) assert (!s.empty ()); char* e (nullptr); + errno = 0; // We must clear it according to POSIX. uint64_t r (strtoull (s.c_str (), &e, 10)); // Can't throw. assert (errno != ERANGE && e == s.c_str () + s.size ()); return r; diff --git a/tests/process-term/driver.cxx b/tests/process-term/driver.cxx index 8487bb7..835272f 100644 --- a/tests/process-term/driver.cxx +++ b/tests/process-term/driver.cxx @@ -98,6 +98,7 @@ main (int argc, const char* argv[]) assert (!s.empty ()); char* e (nullptr); + errno = 0; // We must clear it according to POSIX. uint64_t r (strtoull (s.c_str (), &e, 10)); // Can't throw. assert (errno != ERANGE && e == s.c_str () + s.size ()); |