comparison buffer.c @ 1046:b8f4b7027191 coverity

merge
author Matt Johnston <matt@ucc.asn.au>
date Tue, 24 Feb 2015 22:48:34 +0800
parents a5b785c12340
children 16584026a1f0
comparison
equal deleted inserted replaced
1014:37c510c2ac7c 1046:b8f4b7027191
97 97
98 buffer* ret; 98 buffer* ret;
99 99
100 ret = buf_new(buf->len); 100 ret = buf_new(buf->len);
101 ret->len = buf->len; 101 ret->len = buf->len;
102 memcpy(ret->data, buf->data, buf->len); 102 if (buf->len > 0) {
103 memcpy(ret->data, buf->data, buf->len);
104 }
103 return ret; 105 return ret;
104 } 106 }
105 107
106 /* Set the length of the buffer */ 108 /* Set the length of the buffer */
107 void buf_setlen(buffer* buf, unsigned int len) { 109 void buf_setlen(buffer* buf, unsigned int len) {
125 dropbear_exit("Bad buf_setpos"); 127 dropbear_exit("Bad buf_setpos");
126 } 128 }
127 buf->pos = pos; 129 buf->pos = pos;
128 } 130 }
129 131
130 /* increment the postion by incr, increasing the buffer length if required */ 132 /* increment the position by incr, increasing the buffer length if required */
131 void buf_incrwritepos(buffer* buf, unsigned int incr) { 133 void buf_incrwritepos(buffer* buf, unsigned int incr) {
132 if (incr > BUF_MAX_INCR || buf->pos + incr > buf->size) { 134 if (incr > BUF_MAX_INCR || buf->pos + incr > buf->size) {
133 dropbear_exit("Bad buf_incrwritepos"); 135 dropbear_exit("Bad buf_incrwritepos");
134 } 136 }
135 buf->pos += incr; 137 buf->pos += incr;