Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions include/csptr/smart_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ CSPTR_INLINE void sfree_stack(void *ptr) {
({ \
struct s_tmp { \
CSPTR_SENTINEL_DEC \
__typeof__(__typeof__(Type)[Length]) value; \
__typeof__(Type) *value; \
f_destructor dtor; \
struct { \
const void *ptr; \
Expand All @@ -81,8 +81,12 @@ CSPTR_INLINE void sfree_stack(void *ptr) {
__VA_ARGS__ \
}; \
void *var = smalloc(sizeof (Type), Length, Kind, ARGS_); \
if (var != NULL) \
memcpy(var, &args.value, sizeof (Type)); \
if (var != NULL) { \
if (args.value != NULL) \
memcpy(var, args.value, sizeof (Type) * Length); \
else \
memset(var, 0, sizeof(Type) * Length); \
} \
var; \
})

Expand Down
2 changes: 1 addition & 1 deletion src/mman.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ CSPTR_INLINE static void dealloc_entry(s_meta *meta, void *ptr) {
if (meta->kind & ARRAY) {
s_meta_array *arr_meta = (void *) (meta + 1);
for (size_t i = 0; i < arr_meta->nmemb; ++i)
meta->dtor((char *) ptr + arr_meta->size * i, user_meta);
meta->dtor((char *) ptr + arr_meta->size * i, arr_meta + 1);
} else
meta->dtor(ptr, user_meta);
}
Expand Down