Skip to content

Commit bd46b60

Browse files
committed
fixed bug reg. negative and zero input
1 parent 22a1cef commit bd46b60

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

bn_mp_to_radix.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ mp_err mp_to_radix(const mp_int *a, char *str, size_t maxlen, size_t *written, i
3131
if (MP_IS_ZERO(a)) {
3232
*str++ = '0';
3333
*str = '\0';
34+
if (written != NULL) {
35+
*written = 2u;
36+
}
3437
return MP_OKAY;
3538
}
3639

@@ -72,8 +75,9 @@ mp_err mp_to_radix(const mp_int *a, char *str, size_t maxlen, size_t *written, i
7275

7376
/* append a NULL so the string is properly terminated */
7477
*str = '\0';
78+
digs++;
7579
if (written != NULL) {
76-
*written = digs + 1;
80+
*written = (a->sign == MP_NEG) ? digs + 1u: digs;
7781
}
7882

7983
LBL_ERR:

0 commit comments

Comments
 (0)