Repository navigation
fix(native): avoid signed overflow in square() - #1519
Open
hutiefang76 wants to merge 1 commit into
Open
hutiefang76 wants to merge 1 commit into
hutiefang76 wants to merge 1 commit into
Conversation
Preserve exact integer squares within the signed 64-bit range and promote larger magnitudes to REAL, matching SQLite multiplication semantics. Fixes xerial#1512 Generated-by: DeepSeek deepseek-v4-pro Generated-by: OpenAI Codex
Author
|
The upstream JDK 21 job reports the four overflow failures seen before the C fix. It runs The verification matrix with the JNI libraries rebuilt from this exact source commit has now passed. The rebuilt libraries are on the separate verification branch linked in the description. |
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.
Fixes #1512.
square()currently multiplies signed 64-bit integers without checking overflow. Keep the exact INTEGER result through +/-3037000499 and promote larger magnitudes to REAL, matching SQLite's multiplication operator. Also correct the unary function's argument-count assertion.The 14 parameterized cases compare both the value and SQLite storage type with
x * x, covering the safe boundaries, the next integers outside them, both long extrema, small integers, REAL inputs and NULL.Validation used a Mac/aarch64 JNI built from the C source with the project's
make native, aftermake clean-native. A custom library name/output directory kept bundled binaries unchanged; Maven'sorg.sqlite.lib.pathandorg.sqlite.lib.nameselected that library.mvn verify: 519 tests, 0 failures/errors, 8 skipped; Spotless passed.This PR contains source and tests only. The official Build Native run 44288275645 built all 24 native targets successfully. Its final automatic push failed with HTTP 403 because the bot token is read-only; the workflow as a whole is therefore failed.
All 24 artifact ZIP digests were checked against GitHub metadata. The generated libraries were recovered through a normal user push solely on a separate verification branch. A fresh JDK 11 full verify using Maven's default JNI loader and the cross-compiled Mac/aarch64 artifact completed with 519 test records: 511 passed, 0 failures/errors and 8 skipped.
Official CI on verification commit aa41ddff22ba is queued; runtime results for other platforms remain pending. This PR's source commit and bundled binaries are unchanged. Upstream PR CI still needs maintainer approval, and tests using older bundled binaries do not validate the C change.
AI assistance: DeepSeek generated the initial patch/tests and performed a first-pass review. Codex checked the complete diff and executed the native validation.