projects
/
u
/
mdw
/
catacomb
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
mptext.c: Fix hopeless incorrectness in raw base conversions.
[u/mdw/catacomb]
/
mptext.c
diff --git
a/mptext.c
b/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);
/* --- 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 --- */
/* --- 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))
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 --- */
/* --- 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)) {
/* --- 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;
if (ops->put("-", 1, p))
return (EOF);
m->f &= ~MP_NEG;