mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-17 19:30:36 +00:00
Fix mbuf_resize(0)
PUBLISHED_FROM=7cab7543db990f7f67b53edca4f65ba45b219711
This commit is contained in:
1 parent
ffa0ddfdbf
commit
1a6bc7c514
1 file changed
+8
-5
+8
-5
@@ -143,11 +143,14 @@ void mbuf_free(struct mbuf *mbuf) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void mbuf_resize(struct mbuf *a, size_t new_size) {
|
void mbuf_resize(struct mbuf *a, size_t new_size) {
|
||||||
char *p;
|
if (new_size > a->size || (new_size < a->size && new_size >= a->len)) {
|
||||||
if ((new_size > a->size || (new_size < a->size && new_size >= a->len)) &&
|
a->buf = (char *) MBUF_REALLOC(a->buf, new_size);
|
||||||
(p = (char *) MBUF_REALLOC(a->buf, new_size)) != NULL) {
|
/*
|
||||||
a->size = new_size;
|
* In case realloc fails, there's not much we can do except set size to 0.
|
||||||
a->buf = p;
|
* Note that NULL is a valid return value from realloc when size == 0, but
|
||||||
|
* that is covered too.
|
||||||
|
*/
|
||||||
|
a->size = (a->buf != NULL ? new_size : 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user