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
These functions are both meant to be used with a null-terminated and
thus non-empty sequence of `char`s. However, there is nothing stopping
call sites from passing zero-length sequences, which would certainly not
be null-terminated and also would cause an underflow in `N - 1`.
Therefore, this commit
- changes the size `N` of the array from `int` to `std::size_t`,
- ensures that compilation will fail if `N = 0`, and
- adds a runtime assertion that fails if the `N`-th `char` is not `\0`.
Note that the runtime assertion should be eliminated by any optimizing
compiler when given a string literal, which is how these functions are
used for the most part (though not exclusively).
PR-URL: #58155
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
0 commit comments