Commit 956a272d622af303859d7239c21272116c108b58
1 parent
4ff837f0
Remove abs calls and pick correct floating point epsilon values (fixes #641)
Showing
3 changed files
with
9 additions
and
4 deletions
README-maintainer
| @@ -98,6 +98,11 @@ CODING RULES | @@ -98,6 +98,11 @@ CODING RULES | ||
| 98 | * Avoid atoi. Use QUtil::string_to_int instead. It does | 98 | * Avoid atoi. Use QUtil::string_to_int instead. It does |
| 99 | overflow/underflow checking. | 99 | overflow/underflow checking. |
| 100 | 100 | ||
| 101 | +* Avoid certain functions that tend to be macros or create compilation | ||
| 102 | + errors on some platforms. Known cases: strcasecmp, abs. Avoid min | ||
| 103 | + and max. If needed, std::min and std::max are okay to use in C++ | ||
| 104 | + code with <algorithm> included. | ||
| 105 | + | ||
| 101 | * Remember to avoid using `operator[]` with `std::string` or | 106 | * Remember to avoid using `operator[]` with `std::string` or |
| 102 | `std::vector`. Instead, use `at()`. See README-hardening.md for | 107 | `std::vector`. Instead, use `at()`. See README-hardening.md for |
| 103 | details. | 108 | details. |
qpdf/qpdf-ctest.c
| @@ -714,7 +714,7 @@ static void test25(char const* infile, | @@ -714,7 +714,7 @@ static void test25(char const* infile, | ||
| 714 | double d = 0.0; | 714 | double d = 0.0; |
| 715 | assert(qpdf_oh_get_value_as_number(qpdf, p_bool, &d) == QPDF_FALSE); | 715 | assert(qpdf_oh_get_value_as_number(qpdf, p_bool, &d) == QPDF_FALSE); |
| 716 | assert((qpdf_oh_get_value_as_number(qpdf, p_int, &d) == QPDF_TRUE) && | 716 | assert((qpdf_oh_get_value_as_number(qpdf, p_int, &d) == QPDF_TRUE) && |
| 717 | - (((d - 1.0) * (d - 1.0)) < 1e-100)); | 717 | + ((d - 1.0) < 1e-6) && ((d - 1.0) > -1e-6)); |
| 718 | assert(qpdf_oh_get_type_code(qpdf, p_int) == ot_integer); | 718 | assert(qpdf_oh_get_type_code(qpdf, p_int) == ot_integer); |
| 719 | assert(strcmp(qpdf_oh_get_type_name(qpdf, p_int), "integer") == 0); | 719 | assert(strcmp(qpdf_oh_get_type_name(qpdf, p_int), "integer") == 0); |
| 720 | assert(qpdf_oh_is_real(qpdf, p_real) && | 720 | assert(qpdf_oh_is_real(qpdf, p_real) && |
qpdf/test_driver.cc
| @@ -3293,11 +3293,11 @@ static void test_85(QPDF& pdf, char const* arg2) | @@ -3293,11 +3293,11 @@ static void test_85(QPDF& pdf, char const* arg2) | ||
| 3293 | assert(s == "42.0"); | 3293 | assert(s == "42.0"); |
| 3294 | double num = 0.0; | 3294 | double num = 0.0; |
| 3295 | assert(oh_i.getValueAsNumber(num)); | 3295 | assert(oh_i.getValueAsNumber(num)); |
| 3296 | - assert(abs(num - 1.0) < 1e-100); | 3296 | + assert(((num - 1.0) < 1e-6) && (num - 1.0 > -1e-6)); |
| 3297 | assert(oh_r.getValueAsNumber(num)); | 3297 | assert(oh_r.getValueAsNumber(num)); |
| 3298 | - assert(abs(num - 42.0) < 1e-100); | 3298 | + assert(((num - 42.0) < 1e-6) && (num - 42.0 > -1e-6)); |
| 3299 | assert(! oh_b.getValueAsNumber(num)); | 3299 | assert(! oh_b.getValueAsNumber(num)); |
| 3300 | - assert(abs(num - 42.0) < 1e-100); | 3300 | + assert(((num - 42.0) < 1e-6) && (num - 42.0 > -1e-6)); |
| 3301 | s = ""; | 3301 | s = ""; |
| 3302 | assert(oh_n.getValueAsName(s)); | 3302 | assert(oh_n.getValueAsName(s)); |
| 3303 | assert(s == "/Test") ; | 3303 | assert(s == "/Test") ; |