From 212ce3a8acf41acbcc9b839c37b9e89e4e7754b1 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 4 Jun 2023 15:33:23 +0100 Subject: util/spkmodem-recv: warn on unhandled exit error my style of C programming is this: always return errno upon exit from the program, or from a thread. handle errno in the calling/forking function. returning errno at the end of main has this intention: if an unhandled error occured, the program exits with non-zero status. a correctly written program should *never* return non-zero at the end of main, and if it does, this indicates a bug in the code (per my code style / philosophy). so, warn the user with a message if this occurs. the intention is that this message should never be printed. do not use assert() for this. i don't believe in that. such a test should always be present, for everyone. Signed-off-by: Leah Rowe --- util/spkmodem_recv/spkmodem-recv.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'util/spkmodem_recv') diff --git a/util/spkmodem_recv/spkmodem-recv.c b/util/spkmodem_recv/spkmodem-recv.c index bf522daa..9bba548f 100644 --- a/util/spkmodem_recv/spkmodem-recv.c +++ b/util/spkmodem_recv/spkmodem-recv.c @@ -56,7 +56,9 @@ main(int argc, char *argv[]) while (!feof(stdin)) handle_audio(); - return errno; + if (errno) + err(errno, "Unhandled error upon exit. Exit status is errno."); + return 0; } void -- cgit v1.2.1