Skip to content

Commit

Permalink
Fix buggy handling of NaN of wrong length.
Browse files Browse the repository at this point in the history
Also, account for the possibility that a test's `argc` is 0.

Fixes #307.
  • Loading branch information
jtv committed Apr 22, 2020
1 parent 61860ef commit 2d68a92
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- Prefer `pg_config` over `pkg-config` for include path (#291).
- Try to plod on if we don't know the PostgreSQL include path.
- Fix error message when starting overlapping transactions and such (#303).
- Fix potential crash when "NaN" isn't 3 bytes long (#307).
7.0.5
- Compile fix for g++ 10: include `<limits>` (#292).
- Cleaned up error-checking of PG results. (#280).
Expand Down
5 changes: 3 additions & 2 deletions src/strconv.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,9 @@ template<typename T> inline T from_string_awful_float(std::string_view text)
case 'n':
// Accept "NaN," "nan," etc.
ok =
((text[1] == 'A' or text[1] == 'a') and
(text[2] == 'N' or text[2] == 'n') and (text[3] == '\0'));
(text.size() == 3 and
(text[1] == 'A' or text[1] == 'a') and
(text[2] == 'N' or text[2] == 'n'));
result = std::numeric_limits<T>::quiet_NaN();
break;

Expand Down
6 changes: 3 additions & 3 deletions test/test_main.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void create_pqxxevents(transaction_base &t)

namespace
{
std::map<char const *, pqxx::test::testfunc> *all_tests = nullptr;
std::map<char const *, pqxx::test::testfunc> *all_tests{nullptr};
} // namespace


Expand All @@ -132,9 +132,9 @@ void register_test(char const name[], pqxx::test::testfunc func)
} // namespace pqxx::test


int main(int, char const *argv[])
int main(int argc, char const *argv[])
{
char const *const test_name = argv[1];
char const *const test_name{(argc > 1) ? argv[1] : nullptr};

int test_count = 0;
std::list<std::string> failed;
Expand Down

0 comments on commit 2d68a92

Please sign in to comment.