summaryrefslogtreecommitdiffhomepage
path: root/buffer.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2020-10-24 18:56:45 +0800
committerMatt Johnston <matt@ucc.asn.au>2020-10-24 18:56:45 +0800
commit037d26f055e4818616ffe5c8c3597451550e59e6 (patch)
tree05cd06345540cda5953fade41d3071a8a8d73c2d /buffer.c
parent1a208c460b412113704c4d5f98585017ee0a6ccf (diff)
Add buf_decrpos()
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/buffer.c b/buffer.c
index 173b8e2..fee41d6 100644
--- a/buffer.c
+++ b/buffer.c
@@ -125,18 +125,23 @@ void buf_incrwritepos(buffer* buf, unsigned int incr) {
}
}
-/* increment the position by incr, negative values are allowed, to
- * decrement the pos*/
-void buf_incrpos(buffer* buf, int incr) {
+/* increment the position by incr */
+void buf_incrpos(buffer* buf, unsigned int incr) {
if (incr > BUF_MAX_INCR
- || incr < -BUF_MAX_INCR
- || (unsigned int)((int)buf->pos + incr) > buf->len
- || ((int)buf->pos + incr) < 0) {
+ || (buf->pos + incr) > buf->len) {
dropbear_exit("Bad buf_incrpos");
}
buf->pos += incr;
}
+/* decrement the position by decr */
+void buf_decrpos(buffer* buf, unsigned int decr) {
+ if (decr > buf->pos) {
+ dropbear_exit("Bad buf_decrpos");
+ }
+ buf->pos -= decr;
+}
+
/* Get a byte from the buffer and increment the pos */
unsigned char buf_getbyte(buffer* buf) {