Commit c119a21
committed
SP int: fixes from review by Claude
1. sp_cond_swap_ct_ex (line ~5524) — XOR typo: b->sign ^= b->sign always
zeroed the sign. Fixed to b->sign ^= t->sign to correctly swap signs.
2. sp_mod_d (line ~7271) — Negative modulo correction was applied even
when the remainder was 0. Added (*r != 0) guard to avoid producing d
instead of 0.
3. sp_lshb (line ~8444) — Left-shift size check was off. Refactored to
correctly distinguish between pure-digit shifts and bit-within-digit
shifts when checking if the result fits, using separate overflow checks
for each case.
4. _sp_mulmod_tmp (line ~12160) — Zero inputs caused an allocation of
size 0, which is problematic. Added an early path: if either operand is
zero, set result to zero and skip the allocation/multiply entirely.
5. sp_mod_2d — copy path (line ~14762) — XMEMCPY copied digits *
SP_WORD_SIZEOF bytes but a may have fewer than digits used digits. Fixed
to copy min(a->used, digits) digits to avoid reading uninitialized
memory.
6. sp_mod_2d — negation loop (line ~14782) — Negation loop iterated
over r->used, which could exceed digits. Fixed to loop over min(r->used,
digits).
7. _sp_sqrmod (line ~17314) — Same zero-input issue as _sp_mulmod_tmp.
Added early zero path to skip the allocation/squaring when input is
zero.
8. sp_lcm (line ~19838) — Typo in sign check: b->sign >= MP_NEG
(comparing against a value that is 1, so >= 1 would also match MP_ZPOS)
changed to b->sign == MP_NEG.1 parent f086e91 commit c119a21
1 file changed
Lines changed: 50 additions & 32 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8546 | 8546 | | |
8547 | 8547 | | |
8548 | 8548 | | |
| 8549 | + | |
| 8550 | + | |
8549 | 8551 | | |
8550 | 8552 | | |
8551 | | - | |
| 8553 | + | |
| 8554 | + | |
| 8555 | + | |
| 8556 | + | |
8552 | 8557 | | |
8553 | 8558 | | |
8554 | 8559 | | |
8555 | | - | |
8556 | | - | |
8557 | 8560 | | |
8558 | 8561 | | |
8559 | 8562 | | |
| |||
12258 | 12261 | | |
12259 | 12262 | | |
12260 | 12263 | | |
12261 | | - | |
12262 | | - | |
12263 | 12264 | | |
12264 | | - | |
12265 | | - | |
12266 | | - | |
| 12265 | + | |
| 12266 | + | |
12267 | 12267 | | |
| 12268 | + | |
| 12269 | + | |
| 12270 | + | |
12268 | 12271 | | |
12269 | | - | |
12270 | | - | |
12271 | | - | |
12272 | | - | |
12273 | | - | |
12274 | | - | |
12275 | | - | |
| 12272 | + | |
| 12273 | + | |
| 12274 | + | |
| 12275 | + | |
12276 | 12276 | | |
12277 | | - | |
12278 | | - | |
| 12277 | + | |
| 12278 | + | |
| 12279 | + | |
| 12280 | + | |
| 12281 | + | |
| 12282 | + | |
| 12283 | + | |
| 12284 | + | |
| 12285 | + | |
| 12286 | + | |
| 12287 | + | |
12279 | 12288 | | |
12280 | 12289 | | |
12281 | 12290 | | |
| |||
14851 | 14860 | | |
14852 | 14861 | | |
14853 | 14862 | | |
14854 | | - | |
| 14863 | + | |
| 14864 | + | |
14855 | 14865 | | |
14856 | 14866 | | |
14857 | 14867 | | |
| |||
14870 | 14880 | | |
14871 | 14881 | | |
14872 | 14882 | | |
| 14883 | + | |
14873 | 14884 | | |
14874 | 14885 | | |
14875 | | - | |
| 14886 | + | |
14876 | 14887 | | |
14877 | 14888 | | |
14878 | 14889 | | |
| |||
17401 | 17412 | | |
17402 | 17413 | | |
17403 | 17414 | | |
17404 | | - | |
17405 | | - | |
17406 | 17415 | | |
17407 | | - | |
17408 | | - | |
17409 | | - | |
| 17416 | + | |
| 17417 | + | |
17410 | 17418 | | |
| 17419 | + | |
| 17420 | + | |
| 17421 | + | |
17411 | 17422 | | |
17412 | | - | |
17413 | | - | |
17414 | | - | |
17415 | | - | |
17416 | | - | |
17417 | | - | |
| 17423 | + | |
| 17424 | + | |
| 17425 | + | |
| 17426 | + | |
| 17427 | + | |
| 17428 | + | |
| 17429 | + | |
| 17430 | + | |
| 17431 | + | |
| 17432 | + | |
| 17433 | + | |
| 17434 | + | |
| 17435 | + | |
| 17436 | + | |
| 17437 | + | |
17418 | 17438 | | |
17419 | 17439 | | |
17420 | | - | |
17421 | | - | |
17422 | 17440 | | |
17423 | 17441 | | |
17424 | 17442 | | |
| |||
0 commit comments