From: Garrett Wollman Date: Wed, 10 Aug 2011 03:50:09 +0000 (-0400) Subject: stds.h: introduce AFS_NONNULL X-Git-Tag: upstream/1.8.0_pre1^2~3421 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=342be3535499c5ecd7d34b4edd43a4655559cb28;p=packages%2Fo%2Fopenafs.git stds.h: introduce AFS_NONNULL AFS_NONNULL wraps the GCC/Clang function attribute __nonnull__, which tells the compiler and the static analyzer that the pointer arguments to a function (or specific ones, if provided) cannot be null. Note that GCC has only limited support for warning about violations of these constraints. Usage examples: int myfunc(struct foo *a, bar_t, struct baz *c) AFS_NONNULL((1)); tells the compiler that the first argument cannot be null (but the third one can). int myfunc2(struct foo *a, bar_t, struct baz *c) AFS_NONNULL(); tells the compiler that both pointer arguments cannot be null. Change-Id: Id81f0c382a6a3bdd9bf9c716eb4091b433129d69 Suggested-by: Simon Wilkinson, comment on change Ic8751737 (#5180) Reviewed-on: http://gerrit.openafs.org/5182 Reviewed-by: Simon Wilkinson Tested-by: BuildBot Reviewed-by: Derrick Brashear --- diff --git a/src/config/stds.h b/src/config/stds.h index 11420508d..53badff38 100644 --- a/src/config/stds.h +++ b/src/config/stds.h @@ -296,14 +296,17 @@ hdr_static_inline(unsigned long) afs_printable_uint32_lu(afs_uint32 d) { return #define AFS_UNUSED __attribute__((unused)) #define AFS_ATTRIBUTE_FORMAT(style,x,y) __attribute__((format(style, x, y))) #define AFS_NORETURN __attribute__((__noreturn__)) +#define AFS_NONNULL(x) __attribute__((__nonnull x)) #elif defined (__clang__) #define AFS_UNUSED __attribute__((unused)) #define AFS_ATTRIBUTE_FORMAT(style,x,y) __attribute__((format(style, x, y))) #define AFS_NORETURN __attribute__((__noreturn__)) +#define AFS_NONNULL(x) __attribute__((__nonnull x)) #else #define AFS_UNUSED #define AFS_ATTRIBUTE_FORMAT(style,x,y) #define AFS_NORETURN +#define AFS_NONNULL(x) #endif #endif /* OPENAFS_CONFIG_AFS_STDS_H */