diff options
author | Cristian RodrÃguez <cristian.rodriguez@opensuse.org> | 2010-12-28 21:10:31 -0300 |
---|---|---|
committer | Simon McVittie <smcv@debian.org> | 2011-01-05 13:13:48 +0000 |
commit | e2be7b92a6d46f02d8d682dd9e51bb494f41e92c (patch) | |
tree | f1509eafcb077e442b4d40a12af8a0c151e8b958 /dbus | |
parent | 56d8d4f58ee60cd4f860a99a2dd47b3f636321b8 (diff) | |
download | dbus-e2be7b92a6d46f02d8d682dd9e51bb494f41e92c.tar.gz |
Annotate dbus_malloc*() functions with __attribute__ malloc and __attribute__ alloc_size
This improves optimization as well catches buffer overflows at compile time.
code like:
foo = dbus_malloc(2);
strcpy(foo, "epicfail");
will emit:
"warning ... will always overflow the destination buffer..."
Signed-off-by: Cristian RodrÃguez <cristian.rodriguez@opensuse.org>
Reviewed-by: Thiago Macieira <thiago@kde.org>
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=32710
Diffstat (limited to 'dbus')
-rw-r--r-- | dbus/dbus-macros.h | 14 | ||||
-rw-r--r-- | dbus/dbus-memory.h | 8 |
2 files changed, 22 insertions, 0 deletions
diff --git a/dbus/dbus-macros.h b/dbus/dbus-macros.h index d1e40ecb..dcd3eebd 100644 --- a/dbus/dbus-macros.h +++ b/dbus/dbus-macros.h @@ -74,6 +74,20 @@ #define _DBUS_GNUC_NORETURN #endif /* !__GNUC__ */ +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) +#define DBUS_MALLOC __attribute__((__malloc__)) +#else +#define DBUS_MALLOC +#endif + +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +#define DBUS_ALLOC_SIZE(x) __attribute__((__alloc_size__(x))) +#define DBUS_ALLOC_SIZE2(x,y) __attribute__((__alloc_size__(x,y))) +#else +#define DBUS_ALLOC_SIZE(x) +#define DBUS_ALLOC_SIZE2(x,y) +#endif + /** @def _DBUS_GNUC_PRINTF * used to tell gcc about printf format strings */ diff --git a/dbus/dbus-memory.h b/dbus/dbus-memory.h index ea28423c..4fd56bd6 100644 --- a/dbus/dbus-memory.h +++ b/dbus/dbus-memory.h @@ -38,10 +38,18 @@ DBUS_BEGIN_DECLS */ DBUS_EXPORT +DBUS_MALLOC +DBUS_ALLOC_SIZE(1) void* dbus_malloc (size_t bytes); + DBUS_EXPORT +DBUS_MALLOC +DBUS_ALLOC_SIZE(1) void* dbus_malloc0 (size_t bytes); + DBUS_EXPORT +DBUS_MALLOC +DBUS_ALLOC_SIZE(2) void* dbus_realloc (void *memory, size_t bytes); DBUS_EXPORT |