Mercurial > dropbear
comparison buffer.c @ 1459:06d52bcb8094
Pointer parameter could be declared as pointing to const
author | Francois Perrad <francois.perrad@gadz.org> |
---|---|
date | Sat, 19 Aug 2017 17:16:13 +0200 |
parents | 6fafb500de88 |
children | 5916af64acd4 |
comparison
equal
deleted
inserted
replaced
1458:bdd3802c8ac6 | 1459:06d52bcb8094 |
---|---|
65 | 65 |
66 m_free(buf); | 66 m_free(buf); |
67 } | 67 } |
68 | 68 |
69 /* overwrite the contents of the buffer to clear it */ | 69 /* overwrite the contents of the buffer to clear it */ |
70 void buf_burn(buffer* buf) { | 70 void buf_burn(const buffer* buf) { |
71 | 71 |
72 m_burn(buf->data, buf->size); | 72 m_burn(buf->data, buf->size); |
73 | 73 |
74 } | 74 } |
75 | 75 |
89 return buf; | 89 return buf; |
90 } | 90 } |
91 | 91 |
92 /* Create a copy of buf, allocating required memory etc. */ | 92 /* Create a copy of buf, allocating required memory etc. */ |
93 /* The new buffer is sized the same as the length of the source buffer. */ | 93 /* The new buffer is sized the same as the length of the source buffer. */ |
94 buffer* buf_newcopy(buffer* buf) { | 94 buffer* buf_newcopy(const buffer* buf) { |
95 | 95 |
96 buffer* ret; | 96 buffer* ret; |
97 | 97 |
98 ret = buf_new(buf->len); | 98 ret = buf_new(buf->len); |
99 ret->len = buf->len; | 99 ret->len = buf->len; |
182 buf->pos++; | 182 buf->pos++; |
183 } | 183 } |
184 | 184 |
185 /* returns an in-place pointer to the buffer, checking that | 185 /* returns an in-place pointer to the buffer, checking that |
186 * the next len bytes from that position can be used */ | 186 * the next len bytes from that position can be used */ |
187 unsigned char* buf_getptr(buffer* buf, unsigned int len) { | 187 unsigned char* buf_getptr(const buffer* buf, unsigned int len) { |
188 | 188 |
189 if (len > BUF_MAX_INCR || buf->pos + len > buf->len) { | 189 if (len > BUF_MAX_INCR || buf->pos + len > buf->len) { |
190 dropbear_exit("Bad buf_getptr"); | 190 dropbear_exit("Bad buf_getptr"); |
191 } | 191 } |
192 return &buf->data[buf->pos]; | 192 return &buf->data[buf->pos]; |
193 } | 193 } |
194 | 194 |
195 /* like buf_getptr, but checks against total size, not used length. | 195 /* like buf_getptr, but checks against total size, not used length. |
196 * This allows writing past the used length, but not past the size */ | 196 * This allows writing past the used length, but not past the size */ |
197 unsigned char* buf_getwriteptr(buffer* buf, unsigned int len) { | 197 unsigned char* buf_getwriteptr(const buffer* buf, unsigned int len) { |
198 | 198 |
199 if (len > BUF_MAX_INCR || buf->pos + len > buf->size) { | 199 if (len > BUF_MAX_INCR || buf->pos + len > buf->size) { |
200 dropbear_exit("Bad buf_getwriteptr"); | 200 dropbear_exit("Bad buf_getwriteptr"); |
201 } | 201 } |
202 return &buf->data[buf->pos]; | 202 return &buf->data[buf->pos]; |