Commit 6927326a6ad100e6c1323f751da4f177fb663231

Steffen Jaeckel 2019-09-02T18:17:23

return error if output-buffer is too small

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
diff --git a/bn_mp_to_radix.c b/bn_mp_to_radix.c
index 9ca9be0..c75ee5b 100644
--- a/bn_mp_to_radix.c
+++ b/bn_mp_to_radix.c
@@ -48,6 +48,7 @@ mp_err mp_to_radix(const mp_int *a, char *str, size_t maxlen, int radix)
    while (!MP_IS_ZERO(&t)) {
       if (--maxlen < 1) {
          /* no more room */
+         err = MP_VAL;
          break;
       }
       if ((err = mp_div_d(&t, (mp_digit)radix, &t, &d)) != MP_OKAY) {
@@ -67,7 +68,7 @@ mp_err mp_to_radix(const mp_int *a, char *str, size_t maxlen, int radix)
    *str = '\0';
 
    mp_clear(&t);
-   return MP_OKAY;
+   return err;
 }
 
 #endif