aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-02-11 13:17:51 +0100
committerJay Berkenbilt <ejb@ql.org>2022-02-11 13:18:33 +0100
commit956a272d622af303859d7239c21272116c108b58 (patch)
treedf4530e0353c4ac721a705c4c4af7cb21b3bf559
parent4ff837f099c4594fbb95463ebfd6199051d0fa30 (diff)
downloadqpdf-956a272d622af303859d7239c21272116c108b58.tar.zst
Remove abs calls and pick correct floating point epsilon values (fixes #641)
-rw-r--r--README-maintainer5
-rw-r--r--qpdf/qpdf-ctest.c2
-rw-r--r--qpdf/test_driver.cc6
3 files changed, 9 insertions, 4 deletions
diff --git a/README-maintainer b/README-maintainer
index 76a4c59c..4b36cf14 100644
--- a/README-maintainer
+++ b/README-maintainer
@@ -98,6 +98,11 @@ CODING RULES
* Avoid atoi. Use QUtil::string_to_int instead. It does
overflow/underflow checking.
+* Avoid certain functions that tend to be macros or create compilation
+ errors on some platforms. Known cases: strcasecmp, abs. Avoid min
+ and max. If needed, std::min and std::max are okay to use in C++
+ code with <algorithm> included.
+
* Remember to avoid using `operator[]` with `std::string` or
`std::vector`. Instead, use `at()`. See README-hardening.md for
details.
diff --git a/qpdf/qpdf-ctest.c b/qpdf/qpdf-ctest.c
index fcaf3ce0..36a50f11 100644
--- a/qpdf/qpdf-ctest.c
+++ b/qpdf/qpdf-ctest.c
@@ -714,7 +714,7 @@ static void test25(char const* infile,
double d = 0.0;
assert(qpdf_oh_get_value_as_number(qpdf, p_bool, &d) == QPDF_FALSE);
assert((qpdf_oh_get_value_as_number(qpdf, p_int, &d) == QPDF_TRUE) &&
- (((d - 1.0) * (d - 1.0)) < 1e-100));
+ ((d - 1.0) < 1e-6) && ((d - 1.0) > -1e-6));
assert(qpdf_oh_get_type_code(qpdf, p_int) == ot_integer);
assert(strcmp(qpdf_oh_get_type_name(qpdf, p_int), "integer") == 0);
assert(qpdf_oh_is_real(qpdf, p_real) &&
diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc
index 65ad4e52..dcae002f 100644
--- a/qpdf/test_driver.cc
+++ b/qpdf/test_driver.cc
@@ -3293,11 +3293,11 @@ static void test_85(QPDF& pdf, char const* arg2)
assert(s == "42.0");
double num = 0.0;
assert(oh_i.getValueAsNumber(num));
- assert(abs(num - 1.0) < 1e-100);
+ assert(((num - 1.0) < 1e-6) && (num - 1.0 > -1e-6));
assert(oh_r.getValueAsNumber(num));
- assert(abs(num - 42.0) < 1e-100);
+ assert(((num - 42.0) < 1e-6) && (num - 42.0 > -1e-6));
assert(! oh_b.getValueAsNumber(num));
- assert(abs(num - 42.0) < 1e-100);
+ assert(((num - 42.0) < 1e-6) && (num - 42.0 > -1e-6));
s = "";
assert(oh_n.getValueAsName(s));
assert(s == "/Test") ;