diff buffer.c @ 1754:064f5be2fc45

Add buf_decrpos()
author Matt Johnston <matt@ucc.asn.au>
date Sat, 24 Oct 2020 18:56:45 +0800
parents ff51d5967e2d
children b688c884dad7
line wrap: on
line diff
--- a/buffer.c	Fri Oct 23 20:53:58 2020 +0800
+++ b/buffer.c	Sat Oct 24 18:56:45 2020 +0800
@@ -125,18 +125,23 @@
 	}
 }
 
-/* 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) {