avoid overflow if clamping a digit with used size 0

This commit is contained in:
JacobBarthelmeh
2024-07-05 13:17:53 -06:00
parent c880fcf822
commit d4cf93c2cf

View File

@ -695,9 +695,11 @@ typedef struct sp_ecc_ctx {
#define sp_clamp(a) \
do { \
int ii; \
for (ii = (int)(a)->used - 1; ii >= 0 && (a)->dp[ii] == 0; ii--) { \
if ((a)->used > 0) { \
for (ii = (int)(a)->used - 1; ii >= 0 && (a)->dp[ii] == 0; ii--) { \
} \
(a)->used = (unsigned int)ii + 1; \
} \
(a)->used = (unsigned int)ii + 1; \
} while (0)
/* Check the compiled and linked math implementation are the same.