Coccinelle script to fix malloc failure logging
Krishna Chaitanya
chaitanya.mgit at gmail.com
Tue Dec 19 05:11:49 PST 2023
Hi,
I am trying to work on a Coccinelle script to fix the logging
for memory allocation failures, but my knowledge of Coccinelle is limited
and only able to come up with the below, which doesn't produce any output.
The script itself is basic and doesn't cover all cases (elseif, os_alloc etc),
it just checks for MSG_ERROR in the if and if not found then add the print.
test.cocci:
@has_print@
expression E, E1, P1;
statement S;
@@
E = os_zalloc(E1);
if (E == NULL) S
<+...
wpa_printf(MSG_ERROR, P1);
...+>
@no_print depends on !has_print@
expression E, E1;
statement S;
@@
E = os_zalloc(E1);
if (E == NULL)
+{
+ wpa_printf(MSG_ERROR, "Failed to allocate memory of size %lu\n",
(unsigned long) E1);
S
+}
Running:
spatch --sp-file test.cocci wpa_supplicant/wpa_supplicant.c --debug
--debug-cpp -o wpa_supplicant/wpa_supplicant.c
I was expecting this to fix at least a few instances. Any suggestions?
More information about the Hostap
mailing list