Skip to content

BUG: Fix signed/unsigned comparisons in the nifti tools - #102

Open
hjmjohnson wants to merge 1 commit into
masterfrom
pr/fix-sign-compare
Open

hjmjohnson wants to merge 1 commit into
masterfrom
pr/fix-sign-compare

Conversation

@hjmjohnson

Copy link
Copy Markdown
Member

Re-submission of #51, reverted from master on 2026-09-24 so it can be
reviewed before merging. Content is unchanged from the original.

Base: master. Independent: nothing has to land before it.

Commits
  • BUG: Fix signed/unsigned comparisons in the nifti tools

Ordering for all the re-submitted work is tracked in #84.

Three -Wsign-compare warnings, each comparing a signed value against an
unsigned one, where the signed operand is silently converted and a
negative value would compare as enormous.

  nifti1_tool.c, nifti_tool.c, fill_cmd_string()
      `len < 0 || len >= remain`, len an int, remain a size_t.  The
      `len < 0` test short-circuits first, so the conversion could not
      actually misfire, but the comparison relies on that ordering to be
      correct.  Made explicit, matching the idiom used a few lines above.

  nifti_tool.c, read_file_text()
      `bytes != len64`, size_t against int64_t.  len64 is validated as
      > 0 and <= INT_MAX immediately above, so the cast is lossless.

(cherry picked from commit 7b37e32)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants