Skip to content

Fix libmisc queue tail deletion and unsigned 32-bit decoding - #87

Merged
tlindner merged 1 commit into
nitros9project:mainfrom
tlindner:codex/libmisc-regression-fixes
Oct 29, 2026
Merged

tlindner merged 1 commit into
nitros9project:mainfrom
tlindner:codex/libmisc-regression-fixes

Conversation

@tlindner

Copy link
Copy Markdown
Member

qDeleteNode stopped its search when the current node had no successor, so the last node in a multi-node queue was never checked. Deleting that node incorrectly returned failure and left it linked in the queue. Continue the search while the current node exists so the tail can be unlinked and its data and node allocations released.

int4 shifted the first input byte as a signed int before casting the completed result to unsigned int. For a leading byte of 0x80 or greater, the 24-bit left shift cannot be represented in a signed 32-bit int and invokes undefined behavior. Convert the first byte to unsigned int before shifting, keeping the resulting addition unsigned as well.

Add a libmisctest executable using the existing TinyTest framework and integrate it into the Unix test and clean targets. Ignore its generated binary alongside the other unit-test executables. Cover queue deletion at the tail, head, middle, and only node, checking the remaining sequence and termination. Cover int4 decoding of zero, a mixed-byte value, the signed boundary, high-bit mixed bytes, and the maximum 32-bit value.

Validation:

  • The tail-deletion regression failed before its fix; the other three queue deletion tests passed.
  • UndefinedBehaviorSanitizer rejected the original int4 implementation when decoding 0x80000000 and passed all five libmisc tests after the fix.
  • make -C build/unix completed successfully with all 59 tests passing.
  • git diff --check passed.

qDeleteNode stopped its search when the current node had no successor,
so the last node in a multi-node queue was never checked. Deleting that
node incorrectly returned failure and left it linked in the queue.
Continue the search while the current node exists so the tail can be
unlinked and its data and node allocations released.

int4 shifted the first input byte as a signed int before casting the
completed result to unsigned int. For a leading byte of 0x80 or greater,
the 24-bit left shift cannot be represented in a signed 32-bit int and
invokes undefined behavior. Convert the first byte to unsigned int before
shifting, keeping the resulting addition unsigned as well.

Add a libmisctest executable using the existing TinyTest framework and
integrate it into the Unix test and clean targets. Ignore its generated
binary alongside the other unit-test executables. Cover queue deletion
at the tail, head, middle, and only node, checking the remaining sequence
and termination. Cover int4 decoding of zero, a mixed-byte value, the
signed boundary, high-bit mixed bytes, and the maximum 32-bit value.

Validation:
- The tail-deletion regression failed before its fix; the other three
  queue deletion tests passed.
- UndefinedBehaviorSanitizer rejected the original int4 implementation
  when decoding 0x80000000 and passed all five libmisc tests after the fix.
- make -C build/unix completed successfully with all 59 tests passing.
- git diff --check passed.
@tlindner
tlindner merged commit 4fbf6aa into nitros9project:main Oct 29, 2026
6 checks passed
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.

2 participants