Skip to content

Commit c5df4fd

Browse files
committed
util.c: assert that format strings are not empty
If any of these format strings are empty, things can go very wrong at runtime, from garbage output to segfaults (e.g. see #22375). This is a static check, so it could be placed in any source file. I chose util.c because according to the comment at the top, it is the home of "any stuff that people couldn't think of a better place for".
1 parent 335f06f commit c5df4fd

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

util.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,23 @@ S_maybe_protect_ro(pTHX_ struct perl_memory_debug_header *header)
121121
# endif
122122
#endif
123123

124+
/* Sanity check: Format strings must not be empty */
125+
STATIC_ASSERT_DECL(sizeof I32df > 1);
126+
STATIC_ASSERT_DECL(sizeof U32of > 1);
127+
STATIC_ASSERT_DECL(sizeof U32uf > 1);
128+
STATIC_ASSERT_DECL(sizeof U32xf > 1);
129+
STATIC_ASSERT_DECL(sizeof U32Xf > 1);
130+
STATIC_ASSERT_DECL(sizeof IVdf > 1);
131+
STATIC_ASSERT_DECL(sizeof UVuf > 1);
132+
STATIC_ASSERT_DECL(sizeof UVof > 1);
133+
STATIC_ASSERT_DECL(sizeof UVxf > 1);
134+
STATIC_ASSERT_DECL(sizeof UVXf > 1);
135+
STATIC_ASSERT_DECL(sizeof NVef > 1);
136+
STATIC_ASSERT_DECL(sizeof NVff > 1);
137+
STATIC_ASSERT_DECL(sizeof NVgf > 1);
138+
STATIC_ASSERT_DECL(sizeof Gid_t_f > 1);
139+
STATIC_ASSERT_DECL(sizeof Uid_t_f > 1);
140+
124141
/*
125142
=for apidoc_section $memory
126143
=for apidoc safesysmalloc

0 commit comments

Comments
 (0)