From: mdw Date: Sat, 3 Mar 2001 12:06:48 +0000 (+0000) Subject: Use 16-bit lengths on MPs, since there's a packet limit of 64K anyway. X-Git-Tag: 1.0.0pre1~2 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/tripe/commitdiff_plain/9a8120904fa2fde909d3aa2101a2184397d881f6?hp=0a9920e2dbc0891b418eed3366b59bb65c21c88c Use 16-bit lengths on MPs, since there's a packet limit of 64K anyway. --- diff --git a/buf.c b/buf.c index f2d9f04d..fdc7856a 100644 --- a/buf.c +++ b/buf.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: buf.c,v 1.2 2001/02/16 21:23:20 mdw Exp $ + * $Id: buf.c,v 1.3 2001/03/03 12:06:48 mdw Exp $ * * Buffer handling * @@ -29,6 +29,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: buf.c,v $ + * Revision 1.3 2001/03/03 12:06:48 mdw + * Use 16-bit lengths on MPs, since there's a packet limit of 64K anyway. + * * Revision 1.2 2001/02/16 21:23:20 mdw * Various minor changes. Check that MPs are in canonical form when * loading. @@ -176,7 +179,45 @@ int buf_putbyte(buf *b, int ch) return (0); } -/* --- @buf_getword@ --- * +/* --- @buf_getu16@ --- * + * + * Arguments: @buf *b@ = pointer to a buffer block + * @uint16 *w@ = where to put the word + * + * Returns: Zero if OK, or nonzero if there wasn't a word there. + * + * Use: Gets a 16-bit word from a buffer. + */ + +int buf_getu16(buf *b, uint16 *w) +{ + if (BENSURE(b, 2)) + return (-1); + *w = LOAD16(b->p); + BSTEP(b, 2); + return (0); +} + +/* --- @buf_putu16@ --- * + * + * Arguments: @buf *b@ = pointer to a buffer block + * @uint16 w@ = word to write + * + * Returns: Zero if OK, nonzero if there wasn't enough space. + * + * Use: Puts a 16-but word in a buffer. + */ + +int buf_putu16(buf *b, uint16 w) +{ + if (BENSURE(b, 2)) + return (-1); + STORE16(b->p, w); + BSTEP(b, 2); + return (0); +} + +/* --- @buf_getu32@ --- * * * Arguments: @buf *b@ = pointer to a buffer block * @uint32 *w@ = where to put the word @@ -186,7 +227,7 @@ int buf_putbyte(buf *b, int ch) * Use: Gets a 32-bit word from a buffer. */ -int buf_getword(buf *b, uint32 *w) +int buf_getu32(buf *b, uint32 *w) { if (BENSURE(b, 4)) return (-1); @@ -195,7 +236,7 @@ int buf_getword(buf *b, uint32 *w) return (0); } -/* --- @buf_putword@ --- * +/* --- @buf_putu32@ --- * * * Arguments: @buf *b@ = pointer to a buffer block * @uint32 w@ = word to write @@ -205,7 +246,7 @@ int buf_getword(buf *b, uint32 *w) * Use: Puts a 32-but word in a buffer. */ -int buf_putword(buf *b, uint32 w) +int buf_putu32(buf *b, uint32 w) { if (BENSURE(b, 4)) return (-1); @@ -225,9 +266,9 @@ int buf_putword(buf *b, uint32 w) mp *buf_getmp(buf *b) { - uint32 sz; + uint16 sz; mp *m; - if (buf_getword(b, &sz) || buf_ensure(b, sz)) + if (buf_getu16(b, &sz) || buf_ensure(b, sz)) return (0); m = mp_loadb(MP_NEW, BCUR(b), sz); if (mp_octets(m) != sz) { @@ -251,7 +292,8 @@ mp *buf_getmp(buf *b) int buf_putmp(buf *b, mp *m) { size_t sz = mp_octets(m); - if (buf_putword(b, sz) || buf_ensure(b, sz)) + assert(sz < MASK16); + if (buf_putu16(b, sz) || buf_ensure(b, sz)) return (-1); mp_storeb(m, BCUR(b), sz); BSTEP(b, sz);