Explorar o código

zero init struct

blueloveTH %!s(int64=2) %!d(string=hai) anos
pai
achega
66423f08a8
Modificáronse 1 ficheiros con 3 adicións e 2 borrados
  1. 3 2
      include/pocketpy/cffi.h

+ 3 - 2
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);
     }