X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/5b7e2ea2181af13a916ea67203552c479d6b9c67..572b324afecc0a7cb2654caf1967e18c8bd813ec:/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;