diff mbox series

[41/41] exit.cocci: use the stdlib EXIT_SUCCESS or EXIT_FAILURE exit status

Message ID 20220321225523.724509-42-gitter.spiros@gmail.com (mailing list archive)
State New, archived
Headers show
Series use the stdlib EXIT_SUCCESS or EXIT_FAILURE exit status | expand

Commit Message

Elia Pinto March 21, 2022, 10:55 p.m. UTC
The C standard specifies two constants, EXIT_SUCCESS and  EXIT_FAILURE, that may
be  passed  to exit() to indicate successful or unsuccessful termination,
respectively. The value of status in exit(status) may be EXIT_SUCCESS,
EXIT_FAILURE, or any other value, though only the least significant 8 bits (that
is, status & 0377) shall be available to a waiting parent proces. So exit(-1)
return 255.

Add a coccinelle semantic patch for using the C standard EXIT_SUCCESS and
EXIT_FAILURE to indicate the program exit status instead of "0" or "1",
respectively. In <stdlib.h> EXIT_FAILURE has the value "1": use EXIT_FAILURE
even if the program uses exit(-1), ie 255, for consistency.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
---
 contrib/coccinelle/exit.cocci | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 contrib/coccinelle/exit.cocci
diff mbox series

Patch

diff --git a/contrib/coccinelle/exit.cocci b/contrib/coccinelle/exit.cocci
new file mode 100644
index 0000000000..ea5c243061
--- /dev/null
+++ b/contrib/coccinelle/exit.cocci
@@ -0,0 +1,24 @@ 
+@@
+@@
+- exit(0);
++ exit(EXIT_SUCCESS);
+@@
+@@
+- _exit(0);
++ _exit(EXIT_SUCCESS);
+@@
+@@
+- exit(1);
++ exit(EXIT_FAILURE);
+@@
+@@
+- _exit(1);
++ _exit(EXIT_FAILURE);
+@@
+@@
+- exit(-1);
++ exit(EXIT_FAILURE);
+@@
+@@
+- _exit(-1);
++ _exit(EXIT_FAILURE);