node icon indicating copy to clipboard operation
node copied to clipboard

src: enforce assumptions in FIXED_ONE_BYTE_STRING

Open tniessen opened this issue 7 months ago • 1 comments

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 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).

tniessen avatar May 04 '25 10:05 tniessen

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:

... and 32 files with indirect coverage changes

: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.

codecov[bot] avatar May 04 '25 11:05 codecov[bot]

ping @nodejs/cpp-reviewers

tniessen avatar Aug 14 '25 14:08 tniessen

I think that this PR is quite good as is.

lemire avatar Aug 14 '25 18:08 lemire

CI: https://ci.nodejs.org/job/node-test-pull-request/68637/

nodejs-github-bot avatar Aug 14 '25 21:08 nodejs-github-bot

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.

tniessen avatar Aug 23 '25 11:08 tniessen

CI: https://ci.nodejs.org/job/node-test-pull-request/68839/

nodejs-github-bot avatar Aug 23 '25 22:08 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/68844/

nodejs-github-bot avatar Aug 24 '25 07:08 nodejs-github-bot

Landed in f86b652bc8beec4aea778bfc621781264dfb6c6a

nodejs-github-bot avatar Aug 24 '25 11:08 nodejs-github-bot