Move neg check

This commit is contained in:
Eric Blankenhorn
2020-09-15 09:12:45 -05:00
parent 6451c4e471
commit 5d69c9f1dc
2 changed files with 11 additions and 11 deletions

View File

@ -5244,11 +5244,6 @@ int mp_radix_size (mp_int *a, int radix, int *size)
/* digs is the digit count */
digs = 0;
/* if it's negative add one for the sign */
if (a->sign == MP_NEG) {
++digs;
}
/* init a copy of the input */
if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
return res;
@ -5274,6 +5269,11 @@ int mp_radix_size (mp_int *a, int radix, int *size)
}
#endif
/* if it's negative add one for the sign */
if (a->sign == MP_NEG) {
++digs;
}
/* return digs + 1, the 1 is for the NULL byte that would be required. */
*size = digs + 1;
return MP_OKAY;

View File

@ -5453,11 +5453,6 @@ int mp_radix_size (mp_int *a, int radix, int *size)
/* digs is the digit count */
digs = 0;
/* if it's negative add one for the sign */
if (a->sign == FP_NEG) {
++digs;
}
#ifdef WOLFSSL_SMALL_STACK
t = (fp_int*)XMALLOC(sizeof(fp_int), NULL, DYNAMIC_TYPE_BIGINT);
if (t == NULL)
@ -5485,11 +5480,16 @@ int mp_radix_size (mp_int *a, int radix, int *size)
#ifndef WC_DISABLE_RADIX_ZERO_PAD
/* For hexadecimal output, add zero padding when number of digits is odd */
if (((a->sign == FP_NEG) ? !(digs & 1) : (digs & 1)) && (radix == 16)) {
if ((digs & 1) && (radix == 16)) {
++digs;
}
#endif
/* if it's negative add one for the sign */
if (a->sign == FP_NEG) {
++digs;
}
/* return digs + 1, the 1 is for the NULL byte that would be required. */
*size = digs + 1;
#ifdef WOLFSSL_SMALL_STACK