Repository navigation
Fix bInt() turning negative numbers into huge positive ones - #11
Merged
Merged
Conversation
bInt() formatted values with sprintf('%u'), which treats them as
unsigned: bInt(-5) bound 9223372036854775807. It now keeps the sign,
truncates floats toward zero as before, and throws
InvalidArgumentException for values outside the integer range
(including INF and NAN) instead of binding a wrong number.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
bInt()formatted its value withsprintf('%u', …), which reads it as unsigned. Every negative number came out wrong:-59223372036854775807-5'-5'9223372036854775807-5-1.99223372036854775807-11.9,'2.5','1e3'1,2,1000'9223372036854775808'(too big)9223372036854775807(silently clamped)InvalidArgumentException1e20,INF,NANInvalidArgumentExceptionPositive values and float truncation behave as before. The
%uformat dates from the initial commit, and no test covered negative numbers.Tests: new
tests/MySQLNumericBindingsTest.php(18 cases, no database needed). The full suite passes against MySQL 8.4 (68 tests), along with PHPStan level 8 and PSR-12.🤖 Generated with Claude Code