src: enforce assumptions in FIXED_ONE_BYTE_STRING
These functions are both meant to be used with a null-terminated and thus non-empty sequence of chars. 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
Nof the array frominttostd::size_t, - ensures that compilation will fail if
N = 0, and - adds a runtime assertion that fails if the
N-thcharis 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).
Codecov Report
:x: Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 89.83%. Comparing base (b85e77b) to head (495fbf5).
:warning: Report is 13 commits behind head on main.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| src/util.h | 33.33% | 0 Missing and 2 partials :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #58155 +/- ##
==========================================
- Coverage 89.83% 89.83% -0.01%
==========================================
Files 666 666
Lines 195340 195352 +12
Branches 38353 38362 +9
==========================================
+ Hits 175492 175493 +1
- Misses 12320 12327 +7
- Partials 7528 7532 +4
| Files with missing lines | Coverage Δ | |
|---|---|---|
| src/util.h | 89.74% <33.33%> (-1.57%) |
:arrow_down: |
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
ping @nodejs/cpp-reviewers
I think that this PR is quite good as is.
CI: https://ci.nodejs.org/job/node-test-pull-request/68637/
One of the GitHub Actions workflows failed for unknown reasons and I do not see the usual option to retry. I suppose the only way is to force-push, which will then require a whole new CI run and re-approval.
CI: https://ci.nodejs.org/job/node-test-pull-request/68839/
CI: https://ci.nodejs.org/job/node-test-pull-request/68844/
Landed in f86b652bc8beec4aea778bfc621781264dfb6c6a