/* If we don't know, assume it's not. */
#define IS_COMPILE_CONSTANT(expr) 0
#endif
+
+#if HAVE_WARN_UNUSED_RESULT
+/**
+ * WARN_UNUSED_RESULT - warn if a function return value is unused.
+ *
+ * Used to mark a function where it is extremely unlikely that the caller
+ * can ignore the result, eg realloc().
+ *
+ * Example:
+ * // buf param may be freed by this; need return value!
+ * static char *WARN_UNUSED_RESULT enlarge(const char *buf, unsigned *size)
+ * {
+ * return realloc(buf, (*size) *= 2);
+ * }
+ */
+#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
+#else
+#define WARN_UNUSED_RESULT
+#endif
#endif /* CCAN_COMPILER_H */
*
* talloc_set_name_const(ptr, ptr)
*/
-char *talloc_append_string(char *orig, const char *append);
+char *WARN_UNUSED_RESULT talloc_append_string(char *orig, const char *append);
/**
* talloc_asprintf_append - sprintf onto the end of a talloc buffer.
* equivalent to:
* talloc_set_name_const(ptr, ptr)
*/
-char *talloc_asprintf_append(char *s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
+char *WARN_UNUSED_RESULT talloc_asprintf_append(char *s, const char *fmt, ...)
+ PRINTF_ATTRIBUTE(2,3);
/**
* talloc_vasprintf - vsprintf into a talloc buffer.
* The talloc_vasprintf_append() function is equivalent to
* talloc_asprintf_append(), except it takes a va_list.
*/
-char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2,0);
+char *WARN_UNUSED_RESULT talloc_vasprintf_append(char *s, const char *fmt, va_list ap)
+ PRINTF_ATTRIBUTE(2,0);
/**
* talloc_set_type - force the name of a pointer to a particular type
size_t talloc_reference_count(const void *ptr);
void *_talloc_reference(const void *context, const void *ptr);
-void *_talloc_realloc(const void *context, void *ptr, size_t size, const char *name);
+void *WARN_UNUSED_RESULT _talloc_realloc(const void *context, void *ptr, size_t size, const char *name);
void *talloc_parent(const void *ptr);
const char *talloc_parent_name(const void *ptr);
void *_talloc_steal(const void *new_ctx, const void *ptr);
void *_talloc_memdup(const void *t, const void *p, size_t size, const char *name);
void *_talloc_array(const void *ctx, size_t el_size, unsigned count, const char *name);
void *_talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const char *name);
-void *_talloc_realloc_array(const void *ctx, void *ptr, size_t el_size, unsigned count, const char *name);
+void *WARN_UNUSED_RESULT _talloc_realloc_array(const void *ctx, void *ptr, size_t el_size, unsigned count, const char *name);
void *talloc_realloc_fn(const void *context, void *ptr, size_t size);
void talloc_show_parents(const void *context, FILE *file);
int talloc_is_parent(const void *context, const void *ptr);
"failed: talloc_realloc() on a referenced pointer should fail\n");
CHECK_BLOCKS("realloc", p1, 4);
- talloc_realloc_size(NULL, p2, 0);
- talloc_realloc_size(NULL, p2, 0);
+ ok1(talloc_realloc_size(NULL, p2, 0) == NULL);
+ ok1(talloc_realloc_size(NULL, p2, 0) == NULL);
CHECK_BLOCKS("realloc", p1, 3);
torture_assert("realloc", talloc_realloc_size(NULL, p1, 0x7fffffff) == NULL,
"failed: oversize talloc should fail\n");
- talloc_realloc_size(NULL, p1, 0);
+ p1 = talloc_realloc_size(NULL, p1, 0);
CHECK_BLOCKS("realloc", root, 1);
CHECK_SIZE("realloc", root, 0);
{
struct torture_context *ctx;
- plan_tests(284);
+ plan_tests(288);
ctx = talloc_add_external(NULL, normal_realloc, test_lock, test_unlock);
torture_local_talloc(NULL);
/* Simple config.h for recent gcc. */
#define HAVE_ALIGNOF 1
-#define HAVE_ATTRIBUTE_CONST 1
#define HAVE_ATTRIBUTE_COLD 1
+#define HAVE_ATTRIBUTE_CONST 1
#define HAVE_ATTRIBUTE_MAY_ALIAS 1
#define HAVE_ATTRIBUTE_PRINTF 1
-#define HAVE_ATTRIBUTE_USED 1
#define HAVE_ATTRIBUTE_UNUSED 1
+#define HAVE_ATTRIBUTE_USED 1
#define HAVE_BIG_ENDIAN 0
+#define HAVE_BSWAP_64 1
#define HAVE_BUILTIN_CHOOSE_EXPR 1
+#define HAVE_BUILTIN_CLZ 1
+#define HAVE_BUILTIN_CLZL 1
+#define HAVE_BUILTIN_CLZLL 1
#define HAVE_BUILTIN_CONSTANT_P 1
#define HAVE_BUILTIN_EXPECT 1
+#define HAVE_BUILTIN_FFSL 1
+#define HAVE_BUILTIN_POPCOUNTL 1
#define HAVE_BUILTIN_TYPES_COMPATIBLE_P 1
+#define HAVE_BYTESWAP_H 1
#define HAVE_GETPAGESIZE 1
#define HAVE_LITTLE_ENDIAN 1
#define HAVE_MMAP 1
#define HAVE_STATEMENT_EXPR 1
#define HAVE_TYPEOF 1
#define HAVE_UTIME 1
-#define HAVE_BUILTIN_CLZ 1
-#define HAVE_BUILTIN_CLZL 1
-#define HAVE_BUILTIN_CLZLL 1
-#define HAVE_BUILTIN_FFSL 1
-#define HAVE_BUILTIN_POPCOUNTL 1
-#define HAVE_BYTESWAP_H 1
-#define HAVE_BSWAP_64 1
+#define HAVE_WARN_UNUSED_RESULT 1