summaryrefslogtreecommitdiffstats
path: root/libtommath/bn_mp_toradix_n.c
diff options
context:
space:
mode:
authorKevin B Kenny <kennykb@acm.org>2005-12-27 17:59:37 (GMT)
committerKevin B Kenny <kennykb@acm.org>2005-12-27 17:59:37 (GMT)
commit98036f8f9d6591f75cbbb744ae789e53250d2459 (patch)
tree3273c8ec1192254a0628eccc71a9b1088fea0f2a /libtommath/bn_mp_toradix_n.c
parentfe06c63182af8cb6b22df8c3cf9c7670c92c320d (diff)
downloadtcl-98036f8f9d6591f75cbbb744ae789e53250d2459.zip
tcl-98036f8f9d6591f75cbbb744ae789e53250d2459.tar.gz
tcl-98036f8f9d6591f75cbbb744ae789e53250d2459.tar.bz2
Import of libtommath 0.37
Diffstat (limited to 'libtommath/bn_mp_toradix_n.c')
-rw-r--r--libtommath/bn_mp_toradix_n.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/libtommath/bn_mp_toradix_n.c b/libtommath/bn_mp_toradix_n.c
index d07ba95..607a4be 100644
--- a/libtommath/bn_mp_toradix_n.c
+++ b/libtommath/bn_mp_toradix_n.c
@@ -27,12 +27,12 @@ int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen)
char *_s = str;
/* check range of the maxlen, radix */
- if (maxlen < 3 || radix < 2 || radix > 64) {
+ if (maxlen < 2 || radix < 2 || radix > 64) {
return MP_VAL;
}
/* quick out if its zero */
- if (mp_iszero(a) == 1) {
+ if (mp_iszero(a) == MP_YES) {
*str++ = '0';
*str = '\0';
return MP_OKAY;
@@ -57,21 +57,20 @@ int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen)
digs = 0;
while (mp_iszero (&t) == 0) {
+ if (--maxlen < 1) {
+ /* no more room */
+ break;
+ }
if ((res = mp_div_d (&t, (mp_digit) radix, &t, &d)) != MP_OKAY) {
mp_clear (&t);
return res;
}
*str++ = mp_s_rmap[d];
++digs;
-
- if (--maxlen == 1) {
- /* no more room */
- break;
- }
}
/* reverse the digits of the string. In this case _s points
- * to the first digit [exluding the sign] of the number]
+ * to the first digit [exluding the sign] of the number
*/
bn_reverse ((unsigned char *)_s, digs);
@@ -85,5 +84,5 @@ int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen)
#endif
/* $Source: /root/tcl/repos-to-convert/tcl/libtommath/bn_mp_toradix_n.c,v $ */
-/* $Revision: 1.1.1.2 $ */
-/* $Date: 2005/09/26 16:31:56 $ */
+/* $Revision: 1.1.1.3 $ */
+/* $Date: 2005/12/27 17:59:38 $ */