You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Harden index_range: const invalid sentinel and overflow-safe range checks (#29)
Make index_range::invalid a const static so the shared sentinel cannot be
mutated by callers.
In vector::remove_range / removing_range, compare the vector size against
range.end directly instead of `range.end + 1`. A valid range guarantees
range.end >= 0, so casting to size_t is safe; this removes the potential
signed-integer overflow at INT_MAX and the signed/unsigned comparison
between size() and an int. Behavior is unchanged for all valid ranges.
Note: the assert/abort-on-misuse contract (e.g. replace_range_at bounds,
zip size mismatches) is intentionally left as-is; it is the library's
documented, death-tested error model and changing it to exceptions is a
separate decision.
* Make precondition checks consistent across debug and release (#29)
The library guarded out-of-bounds and size-mismatch operations with assert,
which the standard disables when NDEBUG is defined. As a result the checks
fired (aborting) in debug but vanished in release, turning operator[] and
replace_range_at into silent undefined behavior / buffer overflows there.
Introduce FCPP_PRECONDITION in compatibility.h: an always-on check that
evaluates its condition and calls std::abort() on failure in every build,
preserving the library's existing fatal error model. Replace the assert /
"assert(false); std::abort();" precondition checks in vector, set and map
with it. Define FCPP_NO_PRECONDITION_CHECKS to compile the checks out for
hot paths whose inputs are already validated.
Debug and release now behave identically; all existing EXPECT_DEATH tests
pass under both build types. Added a death test for map's const operator[]
with a missing key, which previously had no coverage.
* docs: document always-on precondition checks and FCPP_NO_PRECONDITION_CHECKS (#29)
---------
Co-authored-by: Claude <noreply@anthropic.com>
Then open the generated ```functional_cpp.sln``` in the ```build``` folder.
93
94
95
+
## Error handling
96
+
Operations with a precondition (for example subscripting with ```operator[]```, ```replace_range_at```, or ```zip``` on containers of unequal size) validate that precondition at runtime. If it is violated, the program is terminated immediately via ```std::abort()```.
97
+
98
+
Unlike the standard library's ```assert```, these checks are **always active and behave identically in debug and release builds** (they are not disabled by ```NDEBUG```), so an out-of-bounds access fails fast in production instead of becoming silent undefined behavior.
99
+
100
+
If you have a performance-critical section whose inputs are already known to be valid, you can compile the checks out by defining ```FCPP_NO_PRECONDITION_CHECKS```:
0 commit comments