mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-23 11:44:53 +00:00
Integrate 1265
This commit is contained in:
1 parent
d88b6a3c95
commit
7061b7202f
2 files changed
+22
No files matched your search
+11
@@ -1370,9 +1370,18 @@ struct mg_connection *mg_http_listen(struct mg_mgr *mgr, const char *url,
|
||||
|
||||
#include <string.h>
|
||||
|
||||
// Not using memset for zeroing memory, cause it can be dropped by compiler
|
||||
// See https://github.com/cesanta/mongoose/pull/1265
|
||||
static void zeromem(volatile unsigned char *buf, size_t len) {
|
||||
if (buf != NULL) {
|
||||
while (len--) *buf++ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int mg_iobuf_resize(struct mg_iobuf *io, size_t new_size) {
|
||||
int ok = 1;
|
||||
if (new_size == 0) {
|
||||
zeromem(io->buf, io->size);
|
||||
free(io->buf);
|
||||
io->buf = NULL;
|
||||
io->len = io->size = 0;
|
||||
@@ -1383,6 +1392,7 @@ int mg_iobuf_resize(struct mg_iobuf *io, size_t new_size) {
|
||||
if (p != NULL) {
|
||||
size_t len = new_size < io->len ? new_size : io->len;
|
||||
if (len > 0) memcpy(p, io->buf, len);
|
||||
zeromem(io->buf, io->size);
|
||||
free(io->buf);
|
||||
io->buf = (unsigned char *) p;
|
||||
io->size = new_size;
|
||||
@@ -1413,6 +1423,7 @@ size_t mg_iobuf_append(struct mg_iobuf *io, const void *buf, size_t len,
|
||||
size_t mg_iobuf_delete(struct mg_iobuf *io, size_t len) {
|
||||
if (len > io->len) len = 0;
|
||||
memmove(io->buf, io->buf + len, io->len - len);
|
||||
zeromem(io->buf + io->len - len, len);
|
||||
io->len -= len;
|
||||
return len;
|
||||
}
|
||||
|
||||
+11
@@ -3,9 +3,18 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
// Not using memset for zeroing memory, cause it can be dropped by compiler
|
||||
// See https://github.com/cesanta/mongoose/pull/1265
|
||||
static void zeromem(volatile unsigned char *buf, size_t len) {
|
||||
if (buf != NULL) {
|
||||
while (len--) *buf++ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int mg_iobuf_resize(struct mg_iobuf *io, size_t new_size) {
|
||||
int ok = 1;
|
||||
if (new_size == 0) {
|
||||
zeromem(io->buf, io->size);
|
||||
free(io->buf);
|
||||
io->buf = NULL;
|
||||
io->len = io->size = 0;
|
||||
@@ -16,6 +25,7 @@ int mg_iobuf_resize(struct mg_iobuf *io, size_t new_size) {
|
||||
if (p != NULL) {
|
||||
size_t len = new_size < io->len ? new_size : io->len;
|
||||
if (len > 0) memcpy(p, io->buf, len);
|
||||
zeromem(io->buf, io->size);
|
||||
free(io->buf);
|
||||
io->buf = (unsigned char *) p;
|
||||
io->size = new_size;
|
||||
@@ -46,6 +56,7 @@ size_t mg_iobuf_append(struct mg_iobuf *io, const void *buf, size_t len,
|
||||
size_t mg_iobuf_delete(struct mg_iobuf *io, size_t len) {
|
||||
if (len > io->len) len = 0;
|
||||
memmove(io->buf, io->buf + len, io->len - len);
|
||||
zeromem(io->buf + io->len - len, len);
|
||||
io->len -= len;
|
||||
return len;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user