[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/maint-0.2.2] Add __attribute__(format)s for our varargs printf/scanf wrappers
commit e28489467233bff4500a70f8a7b22e42ca3b3e68
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Wed May 30 12:14:38 2012 -0400
Add __attribute__(format)s for our varargs printf/scanf wrappers
It turns out that if you set the third argument of
__attribute__(format) to 0, GCC and Clang will check the format
argument without expecting to find variadic arguments. This is the
correct behavior for vsnprintf, vasprintf, and vscanf.
I'm hoping this will fix bug 5969 (a clang warning) by telling clang that
the format argument to tor_vasprintf is indeed a format string.
---
changes/bug5969_022 | 7 +++++++
src/common/compat.h | 5 +++--
src/common/util.h | 6 +++++-
3 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/changes/bug5969_022 b/changes/bug5969_022
new file mode 100644
index 0000000..57c8744
--- /dev/null
+++ b/changes/bug5969_022
@@ -0,0 +1,7 @@
+ o Minor bugfixes
+ - Fix a build warning with Clang 3.1 related to our use of vasprint.
+ Fix for bug 5969. Bugfix on 0.2.2.11-alpha.
+
+ o Compilation improvements:
+ - Tell GCC and Clang to check for any errors in format strings passed
+ to the tor_v*(print|scan)f functions.
diff --git a/src/common/compat.h b/src/common/compat.h
index d2f1fd1..fc70caf 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -261,11 +261,12 @@ void tor_munmap_file(tor_mmap_t *handle) ATTR_NONNULL((1));
int tor_snprintf(char *str, size_t size, const char *format, ...)
CHECK_PRINTF(3,4) ATTR_NONNULL((1,3));
int tor_vsnprintf(char *str, size_t size, const char *format, va_list args)
- ATTR_NONNULL((1,3));
+ CHECK_PRINTF(3,0) ATTR_NONNULL((1,3));
int tor_asprintf(char **strp, const char *fmt, ...)
CHECK_PRINTF(2,3);
-int tor_vasprintf(char **strp, const char *fmt, va_list args);
+int tor_vasprintf(char **strp, const char *fmt, va_list args)
+ CHECK_PRINTF(2,0);
const void *tor_memmem(const void *haystack, size_t hlen, const void *needle,
size_t nlen) ATTR_PURE ATTR_NONNULL((1,3));
diff --git a/src/common/util.h b/src/common/util.h
index b9db25c..d477156 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -211,7 +211,11 @@ const char *escaped(const char *string);
struct smartlist_t;
void wrap_string(struct smartlist_t *out, const char *string, size_t width,
const char *prefix0, const char *prefixRest);
-int tor_vsscanf(const char *buf, const char *pattern, va_list ap);
+int tor_vsscanf(const char *buf, const char *pattern, va_list ap)
+#ifdef __GNUC__
+ __attribute__((format(scanf, 2, 0)))
+#endif
+ ;
int tor_sscanf(const char *buf, const char *pattern, ...)
#ifdef __GNUC__
__attribute__((format(scanf, 2, 3)))
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits