commit fedb3e46ec39e2e980eb1ae25138e9e0b310d084 Author: rl1987 rl1987@sdf.lonestar.org Date: Tue Jul 3 12:33:09 2018 +0300
Remove ATTR_NONNULL macro --- changes/ticket26527 | 3 +++ src/lib/cc/compat_compiler.h | 11 ----------- src/lib/fs/mmap.h | 4 ++-- src/lib/malloc/util_malloc.h | 8 ++++---- src/lib/string/compat_string.h | 4 ++-- src/lib/string/printf.h | 4 ++-- src/lib/string/util_string.h | 24 ++++++++++++------------ 7 files changed, 25 insertions(+), 33 deletions(-)
diff --git a/changes/ticket26527 b/changes/ticket26527 new file mode 100644 index 000000000..ea1d650fe --- /dev/null +++ b/changes/ticket26527 @@ -0,0 +1,3 @@ + o Code simplification and refactoring: + - Remove ATTR_NONNULL macro from codebase. Resolves + ticket 26527. diff --git a/src/lib/cc/compat_compiler.h b/src/lib/cc/compat_compiler.h index c631a7e82..084923eb0 100644 --- a/src/lib/cc/compat_compiler.h +++ b/src/lib/cc/compat_compiler.h @@ -125,16 +125,6 @@ #define ATTR_MALLOC __attribute__((malloc)) #define ATTR_NORETURN __attribute__((noreturn)) #define ATTR_WUR __attribute__((warn_unused_result)) -/* Alas, nonnull is not at present a good idea for us. We'd like to get - * warnings when we pass NULL where we shouldn't (which nonnull does, albeit - * spottily), but we don't want to tell the compiler to make optimizations - * with the assumption that the argument can't be NULL (since this would make - * many of our checks go away, and make our code less robust against - * programming errors). Unfortunately, nonnull currently does both of these - * things, and there's no good way to split them up. - * - * #define ATTR_NONNULL(x) __attribute__((nonnull x)) */ -#define ATTR_NONNULL(x) #define ATTR_UNUSED __attribute__ ((unused))
/** Macro: Evaluates to <b>exp</b> and hints the compiler that the value @@ -158,7 +148,6 @@ #define ATTR_CONST #define ATTR_MALLOC #define ATTR_NORETURN -#define ATTR_NONNULL(x) #define ATTR_UNUSED #define ATTR_WUR #define PREDICT_LIKELY(exp) (exp) diff --git a/src/lib/fs/mmap.h b/src/lib/fs/mmap.h index 125f36880..8d6ca9a0e 100644 --- a/src/lib/fs/mmap.h +++ b/src/lib/fs/mmap.h @@ -35,7 +35,7 @@ typedef struct tor_mmap_t {
} tor_mmap_t;
-tor_mmap_t *tor_mmap_file(const char *filename) ATTR_NONNULL((1)); -int tor_munmap_file(tor_mmap_t *handle) ATTR_NONNULL((1)); +tor_mmap_t *tor_mmap_file(const char *filename); +int tor_munmap_file(tor_mmap_t *handle);
#endif diff --git a/src/lib/malloc/util_malloc.h b/src/lib/malloc/util_malloc.h index 88ecc0453..a1e953117 100644 --- a/src/lib/malloc/util_malloc.h +++ b/src/lib/malloc/util_malloc.h @@ -21,13 +21,13 @@ void *tor_malloc_zero_(size_t size) ATTR_MALLOC; void *tor_calloc_(size_t nmemb, size_t size) ATTR_MALLOC; void *tor_realloc_(void *ptr, size_t size); void *tor_reallocarray_(void *ptr, size_t size1, size_t size2); -char *tor_strdup_(const char *s) ATTR_MALLOC ATTR_NONNULL((1)); +char *tor_strdup_(const char *s) ATTR_MALLOC; char *tor_strndup_(const char *s, size_t n) - ATTR_MALLOC ATTR_NONNULL((1)); + ATTR_MALLOC; void *tor_memdup_(const void *mem, size_t len) - ATTR_MALLOC ATTR_NONNULL((1)); + ATTR_MALLOC; void *tor_memdup_nulterm_(const void *mem, size_t len) - ATTR_MALLOC ATTR_NONNULL((1)); + ATTR_MALLOC; void tor_free_(void *mem);
/** Release memory allocated by tor_malloc, tor_realloc, tor_strdup, diff --git a/src/lib/string/compat_string.h b/src/lib/string/compat_string.h index 0a4ce0175..34490bce0 100644 --- a/src/lib/string/compat_string.h +++ b/src/lib/string/compat_string.h @@ -41,10 +41,10 @@ static inline int strcasecmp(const char *a, const char *b, size_t n) { #endif /* defined __APPLE__ */
#ifndef HAVE_STRLCAT -size_t strlcat(char *dst, const char *src, size_t siz) ATTR_NONNULL((1,2)); +size_t strlcat(char *dst, const char *src, size_t siz); #endif #ifndef HAVE_STRLCPY -size_t strlcpy(char *dst, const char *src, size_t siz) ATTR_NONNULL((1,2)); +size_t strlcpy(char *dst, const char *src, size_t siz); #endif
char *tor_strtok_r_impl(char *str, const char *sep, char **lasts); diff --git a/src/lib/string/printf.h b/src/lib/string/printf.h index 2f4620654..69b724379 100644 --- a/src/lib/string/printf.h +++ b/src/lib/string/printf.h @@ -13,9 +13,9 @@ #include <stddef.h>
int tor_snprintf(char *str, size_t size, const char *format, ...) - CHECK_PRINTF(3,4) ATTR_NONNULL((1,3)); + CHECK_PRINTF(3,4); int tor_vsnprintf(char *str, size_t size, const char *format, va_list args) - CHECK_PRINTF(3,0) ATTR_NONNULL((1,3)); + CHECK_PRINTF(3,0);
int tor_asprintf(char **strp, const char *fmt, ...) CHECK_PRINTF(2,3); diff --git a/src/lib/string/util_string.h b/src/lib/string/util_string.h index bdc2e77ce..75407d5ff 100644 --- a/src/lib/string/util_string.h +++ b/src/lib/string/util_string.h @@ -12,29 +12,29 @@ #include <stddef.h>
const void *tor_memmem(const void *haystack, size_t hlen, const void *needle, - size_t nlen) ATTR_NONNULL((1,3)); + size_t nlen); const void *tor_memstr(const void *haystack, size_t hlen, - const char *needle) ATTR_NONNULL((1,3)); + const char *needle); int tor_mem_is_zero(const char *mem, size_t len); int tor_digest_is_zero(const char *digest); int tor_digest256_is_zero(const char *digest);
/** Allowable characters in a hexadecimal string. */ #define HEX_CHARACTERS "0123456789ABCDEFabcdef" -void tor_strlower(char *s) ATTR_NONNULL((1)); -void tor_strupper(char *s) ATTR_NONNULL((1)); -int tor_strisprint(const char *s) ATTR_NONNULL((1)); -int tor_strisnonupper(const char *s) ATTR_NONNULL((1)); +void tor_strlower(char *s); +void tor_strupper(char *s); +int tor_strisprint(const char *s); +int tor_strisnonupper(const char *s); int tor_strisspace(const char *s); int strcmp_opt(const char *s1, const char *s2); -int strcmpstart(const char *s1, const char *s2) ATTR_NONNULL((1,2)); -int strcmp_len(const char *s1, const char *s2, size_t len) ATTR_NONNULL((1,2)); -int strcasecmpstart(const char *s1, const char *s2) ATTR_NONNULL((1,2)); -int strcmpend(const char *s1, const char *s2) ATTR_NONNULL((1,2)); -int strcasecmpend(const char *s1, const char *s2) ATTR_NONNULL((1,2)); +int strcmpstart(const char *s1, const char *s2); +int strcmp_len(const char *s1, const char *s2, size_t len); +int strcasecmpstart(const char *s1, const char *s2); +int strcmpend(const char *s1, const char *s2); +int strcasecmpend(const char *s1, const char *s2); int fast_memcmpstart(const void *mem, size_t memlen, const char *prefix);
-void tor_strstrip(char *s, const char *strip) ATTR_NONNULL((1,2)); +void tor_strstrip(char *s, const char *strip);
const char *eat_whitespace(const char *s); const char *eat_whitespace_eos(const char *s, const char *eos);
tor-commits@lists.torproject.org