mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-10 16:31:44 +00:00
Introduce mg_calloc
This commit is contained in:
1 parent
5f1f4a0df8
commit
074ef5197b
26 files changed
+259
-313
No files matched your search
+4
-5
@@ -12,18 +12,17 @@ int mg_iobuf_resize(struct mg_iobuf *io, size_t new_size) {
|
||||
new_size = roundup(new_size, io->align);
|
||||
if (new_size == 0) {
|
||||
mg_bzero(io->buf, io->size);
|
||||
free(io->buf);
|
||||
mg_free(io->buf);
|
||||
io->buf = NULL;
|
||||
io->len = io->size = 0;
|
||||
} else if (new_size != io->size) {
|
||||
// NOTE(lsm): do not use realloc here. Use calloc/free only, to ease the
|
||||
// porting to some obscure platforms like FreeRTOS
|
||||
void *p = calloc(1, new_size);
|
||||
// NOTE(lsm): do not use realloc here. Use mg_calloc/mg_free only
|
||||
void *p = mg_calloc(1, new_size);
|
||||
if (p != NULL) {
|
||||
size_t len = new_size < io->len ? new_size : io->len;
|
||||
if (len > 0 && io->buf != NULL) memmove(p, io->buf, len);
|
||||
mg_bzero(io->buf, io->size);
|
||||
free(io->buf);
|
||||
mg_free(io->buf);
|
||||
io->buf = (unsigned char *) p;
|
||||
io->size = new_size;
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user