Skip to content

Commit abc6ffd

Browse files
jpnurmiclaude
andcommitted
make SENTRY_MAKE zero-initialize and drop SENTRY_MAKE_0
Collapse the two allocation macros into one. All SENTRY_MAKE call sites are small control structs where the memset cost is negligible, and zero-init by default eliminates a class of uninitialized-read footguns when struct fields are added later. On the signal-handler path the page allocator already returns zeroed mmap pages, so behavior is unchanged there. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f96fb90 commit abc6ffd

19 files changed

Lines changed: 33 additions & 37 deletions

src/backends/native/sentry_crash_ipc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
sentry_crash_ipc_t *
2020
sentry__crash_ipc_init_app(sem_t *init_sem)
2121
{
22-
sentry_crash_ipc_t *ipc = SENTRY_MAKE_0(sentry_crash_ipc_t);
22+
sentry_crash_ipc_t *ipc = SENTRY_MAKE(sentry_crash_ipc_t);
2323
if (!ipc) {
2424
return NULL;
2525
}
@@ -174,7 +174,7 @@ sentry_crash_ipc_t *
174174
sentry__crash_ipc_init_daemon(
175175
pid_t app_pid, uint64_t app_tid, int notify_eventfd, int ready_eventfd)
176176
{
177-
sentry_crash_ipc_t *ipc = SENTRY_MAKE_0(sentry_crash_ipc_t);
177+
sentry_crash_ipc_t *ipc = SENTRY_MAKE(sentry_crash_ipc_t);
178178
if (!ipc) {
179179
return NULL;
180180
}
@@ -310,7 +310,7 @@ sentry__crash_ipc_free(sentry_crash_ipc_t *ipc)
310310
sentry_crash_ipc_t *
311311
sentry__crash_ipc_init_app(sem_t *init_sem)
312312
{
313-
sentry_crash_ipc_t *ipc = SENTRY_MAKE_0(sentry_crash_ipc_t);
313+
sentry_crash_ipc_t *ipc = SENTRY_MAKE(sentry_crash_ipc_t);
314314
if (!ipc) {
315315
return NULL;
316316
}
@@ -467,7 +467,7 @@ sentry_crash_ipc_t *
467467
sentry__crash_ipc_init_daemon(
468468
pid_t app_pid, uint64_t app_tid, int notify_pipe_read, int ready_pipe_write)
469469
{
470-
sentry_crash_ipc_t *ipc = SENTRY_MAKE_0(sentry_crash_ipc_t);
470+
sentry_crash_ipc_t *ipc = SENTRY_MAKE(sentry_crash_ipc_t);
471471
if (!ipc) {
472472
return NULL;
473473
}
@@ -600,7 +600,7 @@ sentry__crash_ipc_free(sentry_crash_ipc_t *ipc)
600600
sentry_crash_ipc_t *
601601
sentry__crash_ipc_init_app(HANDLE init_mutex)
602602
{
603-
sentry_crash_ipc_t *ipc = SENTRY_MAKE_0(sentry_crash_ipc_t);
603+
sentry_crash_ipc_t *ipc = SENTRY_MAKE(sentry_crash_ipc_t);
604604
if (!ipc) {
605605
return NULL;
606606
}
@@ -729,7 +729,7 @@ sentry__crash_ipc_init_daemon(pid_t app_pid, uint64_t app_tid,
729729
(void)event_handle;
730730
(void)ready_event_handle;
731731

732-
sentry_crash_ipc_t *ipc = SENTRY_MAKE_0(sentry_crash_ipc_t);
732+
sentry_crash_ipc_t *ipc = SENTRY_MAKE(sentry_crash_ipc_t);
733733
if (!ipc) {
734734
return NULL;
735735
}

src/backends/sentry_backend_breakpad.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ sentry__backend_preload(void)
331331
sentry_backend_t *
332332
sentry__backend_new(void)
333333
{
334-
auto *backend = SENTRY_MAKE_0(sentry_backend_t);
334+
auto *backend = SENTRY_MAKE(sentry_backend_t);
335335
if (!backend) {
336336
return nullptr;
337337
}

src/backends/sentry_backend_crashpad.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ sentry__backend_preload(void)
10371037
sentry_backend_t *
10381038
sentry__backend_new(void)
10391039
{
1040-
auto *backend = SENTRY_MAKE_0(sentry_backend_t);
1040+
auto *backend = SENTRY_MAKE(sentry_backend_t);
10411041
if (!backend) {
10421042
return nullptr;
10431043
}

src/backends/sentry_backend_inproc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1810,7 +1810,7 @@ sentry__backend_preload(void)
18101810
sentry_backend_t *
18111811
sentry__backend_new(void)
18121812
{
1813-
sentry_backend_t *backend = SENTRY_MAKE_0(sentry_backend_t);
1813+
sentry_backend_t *backend = SENTRY_MAKE(sentry_backend_t);
18141814
if (!backend) {
18151815
return NULL;
18161816
}

src/backends/sentry_backend_native.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ native_backend_startup(
117117
sentry__mutex_unlock(&g_ipc_init_mutex);
118118
#endif
119119

120-
native_backend_state_t *state = SENTRY_MAKE_0(native_backend_state_t);
120+
native_backend_state_t *state = SENTRY_MAKE(native_backend_state_t);
121121
if (!state) {
122122
return 1;
123123
}
@@ -929,7 +929,7 @@ sentry__backend_preload(void)
929929
sentry_backend_t *
930930
sentry__backend_new(void)
931931
{
932-
sentry_backend_t *backend = SENTRY_MAKE_0(sentry_backend_t);
932+
sentry_backend_t *backend = SENTRY_MAKE(sentry_backend_t);
933933
if (!backend) {
934934
return NULL;
935935
}

src/sentry_alloc.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@
33

44
#include "sentry_boot.h"
55

6-
/**
7-
* This is a shortcut for a typed `malloc`.
8-
*/
9-
#define SENTRY_MAKE(Type) (Type *)sentry_malloc(sizeof(Type))
6+
void *sentry__calloc(size_t count, size_t size);
107

118
/**
12-
* This is a typed `calloc` that zero-initializes the allocation.
9+
* This is a shortcut for a typed `calloc` that zero-initializes the allocation.
1310
*/
14-
void *sentry__calloc(size_t count, size_t size);
15-
#define SENTRY_MAKE_0(Type) (Type *)sentry__calloc(1, sizeof(Type))
11+
#define SENTRY_MAKE(Type) (Type *)sentry__calloc(1, sizeof(Type))
1612

1713
#endif

src/sentry_attachment.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ sentry__attachment_from_path(sentry_path_t *path)
7474
if (!path) {
7575
return NULL;
7676
}
77-
sentry_attachment_t *attachment = SENTRY_MAKE_0(sentry_attachment_t);
77+
sentry_attachment_t *attachment = SENTRY_MAKE(sentry_attachment_t);
7878
if (!attachment) {
7979
sentry__path_free(path);
8080
return NULL;
@@ -94,7 +94,7 @@ sentry__attachment_from_buffer(
9494
sentry__path_free(filename);
9595
return NULL;
9696
}
97-
sentry_attachment_t *attachment = SENTRY_MAKE_0(sentry_attachment_t);
97+
sentry_attachment_t *attachment = SENTRY_MAKE(sentry_attachment_t);
9898
if (!attachment) {
9999
sentry__path_free(filename);
100100
return NULL;
@@ -214,7 +214,7 @@ attachment_clone(const sentry_attachment_t *attachment)
214214
return NULL;
215215
}
216216

217-
sentry_attachment_t *clone = SENTRY_MAKE_0(sentry_attachment_t);
217+
sentry_attachment_t *clone = SENTRY_MAKE(sentry_attachment_t);
218218
if (!clone) {
219219
return NULL;
220220
}

src/sentry_batcher.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ sentry_batcher_t *
2323
sentry__batcher_new(
2424
sentry_batch_func_t batch_func, sentry_data_category_t data_category)
2525
{
26-
sentry_batcher_t *batcher = SENTRY_MAKE_0(sentry_batcher_t);
26+
sentry_batcher_t *batcher = SENTRY_MAKE(sentry_batcher_t);
2727
if (!batcher) {
2828
return NULL;
2929
}

src/sentry_hint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
sentry_hint_t *
1111
sentry_hint_new(void)
1212
{
13-
sentry_hint_t *hint = SENTRY_MAKE_0(sentry_hint_t);
13+
sentry_hint_t *hint = SENTRY_MAKE(sentry_hint_t);
1414
if (!hint) {
1515
return NULL;
1616
}

src/sentry_options.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
sentry_options_t *
1515
sentry_options_new(void)
1616
{
17-
sentry_options_t *opts = SENTRY_MAKE_0(sentry_options_t);
17+
sentry_options_t *opts = SENTRY_MAKE(sentry_options_t);
1818
if (!opts) {
1919
return NULL;
2020
}

0 commit comments

Comments
 (0)