X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/45c0fd363937c6e9b05da04a9167e9912c05ca0c..5d01b1b9514a258c5a3c201e944f676cb2c467f0:/mptext.c diff --git a/mptext.c b/mptext.c index ee73fed..8c00e34 100644 --- 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;