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
#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
*/
*/
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