From 0f82a2c3c3177b379e2ac32a98e4505fc584cd65 Mon Sep 17 00:00:00 2001 From: Giacomo Tesio Date: Wed, 18 Jan 2017 01:47:28 +0100 Subject: [PATCH] libmp: fix #5: mptole takes `p` xor `pp` According to http://man.cat-v.org/9front/2/mp mptole either take p or pp: > Mptobe and mptole convert an mpint to a byte array. The > former creates a big endian representation, the latter a > little endian one. If the destination buf is not nil, it > specifies the buffer of length blen for the result. If the > representation is less than blen bytes, the rest of the > buffer is zero filled. **If buf is nil**, then a buffer is > allocated and a pointer to it is deposited in the location > pointed to by **bufp**. Sign is ignored in these conversions, > i.e., the byte array version is always positive. Assert accordingly. --- sys/src/lib/mp/port/mptole.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sys/src/lib/mp/port/mptole.c b/sys/src/lib/mp/port/mptole.c index 9934fb0..cc4b274 100644 --- a/sys/src/lib/mp/port/mptole.c +++ b/sys/src/lib/mp/port/mptole.c @@ -10,6 +10,7 @@ mptole(mpint *b, uint8_t *p, uint32_t n, uint8_t **pp) { int m; + assert((p == nil) != (pp == nil)) m = (mpsignif(b)+7)/8; if(m == 0) m++;