Commit f6d8da102ec0601e53952b0f8123c4dc345ee966

Authored by m-holger
1 parent 18b26a2b

Refactor to consolidate assertion logic with `util::assertion` function.

README-maintainer.md
... ... @@ -209,6 +209,11 @@ Building docs from pull requests is also enabled.
209 209 This requires inclusion of 'assert_debug.h' or 'Util.hh'. Remember
210 210 that these (except for 'qpdf_static_expect') are only checked in
211 211 debug builds.
  212 + * Use 'util::assertion' when checks should also be carried out in
  213 + release code in preference to throwing logic_errors directly
  214 + unless it is practical and desirable to test violations during
  215 + CI testing. This avoids obscuring genuine gaps in coverage with
  216 + noise generated by unreachable sanity checks.
212 217  
213 218 These rules are enforced by the check-assert test. This practices
214 219 serves to
... ...
libqpdf/qpdf/Util.hh
... ... @@ -3,6 +3,7 @@
3 3  
4 4 #include <qpdf/assert_debug.h>
5 5  
  6 +#include <stdexcept>
6 7 #include <string>
7 8 #include <utility>
8 9  
... ... @@ -12,6 +13,17 @@ namespace qpdf::util
12 13 // inline functions, some of which are exposed as regular functions in QUtil. Implementations
13 14 // are in QUtil.cc.
14 15  
  16 + // Throw a logic_error if 'cond' does not hold.
  17 + //
  18 + // DO NOT USE unless it is impractical or unnecessary to cover violations during CI Testing.
  19 + inline void
  20 + assertion(bool cond, std::string const msg)
  21 + {
  22 + if (!cond) {
  23 + throw std::logic_error(msg);
  24 + }
  25 + }
  26 +
15 27 inline constexpr char
16 28 hex_decode_char(char digit)
17 29 {
... ...