@@ -120,9 +120,13 @@ int mp_print_strn(const mp_print_t *print, const char *str, mp_uint_t len, int f
120120// We can use 16 characters for 32-bit and 32 characters for 64-bit
121121#define INT_BUF_SIZE (sizeof(mp_int_t) * 4)
122122
123- // This function is used by stmhal port to implement printf.
123+ // Our mp_vprintf function below does not support the '#' format modifier to
124+ // print the prefix of a non-base-10 number, so we don't need code for this.
125+ #define SUPPORT_INT_BASE_PREFIX (0)
126+
127+ // This function is used exclusively by mp_vprintf to format ints.
124128// It needs to be a separate function to mp_print_mp_int, since converting to a mp_int looses the MSB.
125- int mp_print_int (const mp_print_t * print , mp_uint_t x , int sgn , int base , int base_char , int flags , char fill , int width ) {
129+ STATIC int mp_print_int (const mp_print_t * print , mp_uint_t x , int sgn , int base , int base_char , int flags , char fill , int width ) {
126130 char sign = 0 ;
127131 if (sgn ) {
128132 if ((mp_int_t )x < 0 ) {
@@ -153,6 +157,7 @@ int mp_print_int(const mp_print_t *print, mp_uint_t x, int sgn, int base, int ba
153157 } while (b > buf && x != 0 );
154158 }
155159
160+ #if SUPPORT_INT_BASE_PREFIX
156161 char prefix_char = '\0' ;
157162
158163 if (flags & PF_FLAG_SHOW_PREFIX ) {
@@ -164,23 +169,28 @@ int mp_print_int(const mp_print_t *print, mp_uint_t x, int sgn, int base, int ba
164169 prefix_char = base_char + 'x' - 'a' ;
165170 }
166171 }
172+ #endif
167173
168174 int len = 0 ;
169175 if (flags & PF_FLAG_PAD_AFTER_SIGN ) {
170176 if (sign ) {
171177 len += mp_print_strn (print , & sign , 1 , flags , fill , 1 );
172178 width -- ;
173179 }
180+ #if SUPPORT_INT_BASE_PREFIX
174181 if (prefix_char ) {
175182 len += mp_print_strn (print , "0" , 1 , flags , fill , 1 );
176183 len += mp_print_strn (print , & prefix_char , 1 , flags , fill , 1 );
177184 width -= 2 ;
178185 }
186+ #endif
179187 } else {
188+ #if SUPPORT_INT_BASE_PREFIX
180189 if (prefix_char && b > & buf [1 ]) {
181190 * (-- b ) = prefix_char ;
182191 * (-- b ) = '0' ;
183192 }
193+ #endif
184194 if (sign && b > buf ) {
185195 * (-- b ) = sign ;
186196 }
0 commit comments