node icon indicating copy to clipboard operation
node copied to clipboard

test: check that sysconf returns a positive value

Open tniessen opened this issue 2 years ago • 2 comments

Static analysis insists that sysconf(_SC_PAGE_SIZE) might return a negative integer (even though it never will). This was supposed to be handled by the existing check EXPECT_GE(page, static_cast<int>(N)). I assume that static analysis does not consider this sufficient because static_cast<int>(N) could be negative or zero if N exceeds INT_MAX (even though it never will).

To resolve this (theoretical) problem, explicitly check that the return value is positive and then cast it to a size_t.

tniessen avatar Sep 16 '22 09:09 tniessen

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

nodejs-github-bot avatar Sep 16 '22 12:09 nodejs-github-bot

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

nodejs-github-bot avatar Sep 16 '22 18:09 nodejs-github-bot

cc @nodejs/cpp-reviewers

tniessen avatar Sep 23 '22 22:09 tniessen

@RaisinTen Thanks for reviewing!

Does coverity pick up static asserts?

Good point, it probably would. Either way, size_t is the semantically correct type here so I'm happy to get rid of int :)

tniessen avatar Sep 25 '22 10:09 tniessen

Landed in 3492320fddf28e15d45b842014549a9ae7dc6ded

nodejs-github-bot avatar Sep 25 '22 10:09 nodejs-github-bot

@RaisinTen Huh, this did not work -- coverity found a new issue. I just realized that EXPECT_* is non-fatal, so that is likely the problem. We can't use ASSERT_* though, so I'll try CHECK_* instead.

Edit: See https://github.com/nodejs/node/pull/44795.

tniessen avatar Sep 26 '22 10:09 tniessen