Release 2.1.3.
[u/mdw/catacomb] / mptext.c
index ee73fed..8c00e34 100644 (file)
--- a/mptext.c
+++ b/mptext.c
@@ -136,8 +136,10 @@ mp *mp_read(mp *m, int radix, const mptext_ops *ops, void *p)
   /* --- Read an initial character --- */
 
   ch = ops->get(p);
-  while (isspace(ch))
-    ch = ops->get(p);
+  if (radix >= 0) {
+    while (isspace(ch))
+      ch = ops->get(p);
+  }
 
   /* --- Handle an initial sign --- */
 
@@ -657,7 +659,7 @@ int mp_write(mp *m, int radix, const mptext_ops *ops, void *p)
   int rc;
 
   if (MP_EQ(m, MP_ZERO))
-    return (ops->put("0", 1, p));
+    return (ops->put(radix > 0 ? "0" : "\0", 1, p));
 
   /* --- Set various things up --- */
 
@@ -676,6 +678,7 @@ int mp_write(mp *m, int radix, const mptext_ops *ops, void *p)
   /* --- If the number is negative, sort that out --- */
 
   if (MP_NEGP(m)) {
+    assert(radix > 0);
     if (ops->put("-", 1, p))
       return (EOF);
     m->f &= ~MP_NEG;