comparison 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
comparison
equal deleted inserted replaced
1753:7c0fcd19e492 1754:064f5be2fc45
123 if (buf->pos > buf->len) { 123 if (buf->pos > buf->len) {
124 buf->len = buf->pos; 124 buf->len = buf->pos;
125 } 125 }
126 } 126 }
127 127
128 /* increment the position by incr, negative values are allowed, to 128 /* increment the position by incr */
129 * decrement the pos*/ 129 void buf_incrpos(buffer* buf, unsigned int incr) {
130 void buf_incrpos(buffer* buf, int incr) {
131 if (incr > BUF_MAX_INCR 130 if (incr > BUF_MAX_INCR
132 || incr < -BUF_MAX_INCR 131 || (buf->pos + incr) > buf->len) {
133 || (unsigned int)((int)buf->pos + incr) > buf->len
134 || ((int)buf->pos + incr) < 0) {
135 dropbear_exit("Bad buf_incrpos"); 132 dropbear_exit("Bad buf_incrpos");
136 } 133 }
137 buf->pos += incr; 134 buf->pos += incr;
135 }
136
137 /* decrement the position by decr */
138 void buf_decrpos(buffer* buf, unsigned int decr) {
139 if (decr > buf->pos) {
140 dropbear_exit("Bad buf_decrpos");
141 }
142 buf->pos -= decr;
138 } 143 }
139 144
140 /* Get a byte from the buffer and increment the pos */ 145 /* Get a byte from the buffer and increment the pos */
141 unsigned char buf_getbyte(buffer* buf) { 146 unsigned char buf_getbyte(buffer* buf) {
142 147