[LEDE-DEV] [PATCH] libubox: Add printf attribute to several functions.
Rosen Penev
rosenp at gmail.com
Tue Nov 1 00:32:39 PDT 2016
Also fixed some formats. Without this attribute, GCC does not see the several functions as variants of the -f family of functions which prevents it from warning about their usage. Might help with optimization too. I avoided defining the attributes in utils.h since different functions have different requirements.
Signed-off by: Rosen Penev <rosenp at gmail.com>
---
blobmsg.c | 5 +++--
ulog.c | 6 +++++-
usock.c | 2 +-
ustream.c | 2 ++
4 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/blobmsg.c b/blobmsg.c
index 1e93376..73f927e 100644
--- a/blobmsg.c
+++ b/blobmsg.c
@@ -227,7 +227,7 @@ blobmsg_open_nested(struct blob_buf *buf, const char *name, bool array)
return (void *)offset;
}
-int
+__attribute__((format(printf, 3, 0))) int
blobmsg_vprintf(struct blob_buf *buf, const char *name, const char *format, va_list arg)
{
va_list arg2;
@@ -248,7 +248,8 @@ blobmsg_vprintf(struct blob_buf *buf, const char *name, const char *format, va_l
return ret;
}
-int
+
+__attribute__((format(printf, 3, 4))) int
blobmsg_printf(struct blob_buf *buf, const char *name, const char *format, ...)
{
va_list ap;
diff --git a/ulog.c b/ulog.c
index 296605d..7a862b3 100644
--- a/ulog.c
+++ b/ulog.c
@@ -86,12 +86,13 @@ static void ulog_defaults(void)
_ulog_initialized = 1;
}
+__attribute__((format(printf, 2, 0)))
static void ulog_kmsg(int priority, const char *fmt, va_list ap)
{
FILE *kmsg;
if ((kmsg = fopen("/dev/kmsg", "r+")) != NULL) {
- fprintf(kmsg, "<%u>", priority);
+ fprintf(kmsg, "<%d>", priority);
if (_ulog_ident)
fprintf(kmsg, "%s: ", _ulog_ident);
@@ -101,6 +102,7 @@ static void ulog_kmsg(int priority, const char *fmt, va_list ap)
}
}
+__attribute__((format(printf, 2, 0)))
static void ulog_stdio(int priority, const char *fmt, va_list ap)
{
FILE *out = stderr;
@@ -111,6 +113,7 @@ static void ulog_stdio(int priority, const char *fmt, va_list ap)
vfprintf(out, fmt, ap);
}
+__attribute__((format(printf, 2, 0)))
static void ulog_syslog(int priority, const char *fmt, va_list ap)
{
vsyslog(priority, fmt, ap);
@@ -141,6 +144,7 @@ void ulog_threshold(int threshold)
_ulog_threshold = threshold;
}
+__attribute__((format(printf, 2, 3)))
void ulog(int priority, const char *fmt, ...)
{
va_list ap;
diff --git a/usock.c b/usock.c
index 0ce5390..0983806 100644
--- a/usock.c
+++ b/usock.c
@@ -247,7 +247,7 @@ const char *usock_port(int port)
if (port < 0 || port > 65535)
return NULL;
- snprintf(buffer, sizeof(buffer), "%u", port);
+ snprintf(buffer, sizeof(buffer), "%d", port);
return buffer;
}
diff --git a/ustream.c b/ustream.c
index d36ce08..2570577 100644
--- a/ustream.c
+++ b/ustream.c
@@ -464,6 +464,7 @@ int ustream_write(struct ustream *s, const char *data, int len, bool more)
#define MAX_STACK_BUFLEN 256
+__attribute__((format(printf, 2, 0)))
int ustream_vprintf(struct ustream *s, const char *format, va_list arg)
{
struct ustream_buf_list *l = &s->w;
@@ -531,6 +532,7 @@ int ustream_vprintf(struct ustream *s, const char *format, va_list arg)
return wr;
}
+__attribute__((format(printf, 2, 3)))
int ustream_printf(struct ustream *s, const char *format, ...)
{
va_list arg;
--
2.7.4
More information about the Lede-dev
mailing list