Skip to content

Commit 226c631

Browse files
committed
Heapmath mp_add_d: fix for when a and c same pointer
When parameters a and c to mp_add_d are the same pointer, c->sign was being set to zero/positive and then a->sign was being checked. Set the c->sign at end as it will always be zero/positive through the code and the sign of the result isn't otherwise used.
1 parent 2c9208b commit 226c631

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

wolfcrypt/src/integer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4425,9 +4425,6 @@ int mp_add_d (mp_int* a, mp_digit b, mp_int* c) /* //NOLINT(misc-no-recursion) *
44254425
/* old number of used digits in c */
44264426
oldused = c->used;
44274427

4428-
/* sign always positive */
4429-
c->sign = MP_ZPOS;
4430-
44314428
/* source alias */
44324429
tmpa = a->dp;
44334430

@@ -4478,6 +4475,9 @@ int mp_add_d (mp_int* a, mp_digit b, mp_int* c) /* //NOLINT(misc-no-recursion) *
44784475
ix = 1;
44794476
}
44804477

4478+
/* sign always positive */
4479+
c->sign = MP_ZPOS;
4480+
44814481
/* now zero to oldused */
44824482
while (ix++ < oldused) {
44834483
*tmpc++ = 0;

0 commit comments

Comments
 (0)