From 66423f08a899304307b73248eb2b19e7d4e0e0cf Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Wed, 11 Oct 2023 21:45:14 +0800 Subject: [PATCH] zero init struct --- include/pocketpy/cffi.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/pocketpy/cffi.h b/include/pocketpy/cffi.h index b4bc9dde..b3cf5917 100644 --- a/include/pocketpy/cffi.h +++ b/include/pocketpy/cffi.h @@ -93,16 +93,17 @@ struct C99Struct{ char* p; int size; - C99Struct(int new_size){ + C99Struct(int new_size, bool zero_init){ this->size = new_size; if(size <= INLINE_SIZE){ p = _inlined; }else{ p = (char*)malloc(size); } + if(zero_init) memset(p, 0, size); } - C99Struct(void* p, int size): C99Struct(size){ + C99Struct(void* p, int size): C99Struct(size, false){ if(p != nullptr) memcpy(this->p, p, size); }