Add error_msg_raw() and friends, replace error_msg("%s", s) uses, enable format
checking, and fix up format checking complaints.
Added out(type, value) function to stat to avoid a zillion printf typecasts.
diff --git a/lib/lib.c b/lib/lib.c
index c89aeb6..8d12b98 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -49,6 +49,18 @@
xexit();
}
+// Die with an error message and strerror(errno)
+void perror_exit(char *msg, ...)
+{
+ va_list va;
+
+ va_start(va, msg);
+ verror_msg(msg, errno, va);
+ va_end(va);
+
+ xexit();
+}
+
// Exit with an error message after showing help text.
void help_exit(char *msg, ...)
{
@@ -65,16 +77,28 @@
xexit();
}
-// Die with an error message and strerror(errno)
-void perror_exit(char *msg, ...)
+// If you want to explicitly disable the printf() behavior (because you're
+// printing user-supplied data, or because android's static checker produces
+// false positives for 'char *s = x ? "blah1" : "blah2"; printf(s);' and it's
+// -Werror there for policy reasons).
+void error_msg_raw(char *msg)
{
- va_list va;
+ error_msg("%s", msg);
+}
- va_start(va, msg);
- verror_msg(msg, errno, va);
- va_end(va);
+void perror_msg_raw(char *msg)
+{
+ perror_msg("%s", msg);
+}
- xexit();
+void error_exit_raw(char *msg)
+{
+ error_exit("%s", msg);
+}
+
+void perror_exit_raw(char *msg)
+{
+ error_exit("%s", msg);
}
// Keep reading until full or EOF
@@ -260,7 +284,7 @@
{
long l = estrtol(str, end, base);
- if (errno) perror_exit("%s", str);
+ if (errno) perror_exit_raw(str);
return l;
}
@@ -525,7 +549,7 @@
if (!strcmp(*argv, "-")) fd=0;
else if (0>(fd = open(*argv, flags, permissions)) && !failok)
- perror_msg("%s", *argv);
+ perror_msg_raw(*argv);
else {
function(fd, *argv);
if (flags & O_CLOEXEC) close(fd);