From ae99a3d76c527699cca11809aafa12fc769a7f8b Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Thu, 14 Sep 2023 08:22:57 -0700 Subject: [PATCH] util: Add more PRINTFLIKE and MALLOCLIKE annotations Reviewed-by: Yonggang Luo Part-of: --- src/util/log.h | 2 +- src/util/ralloc.h | 22 +++++++++++----------- src/util/string_buffer.h | 2 +- src/util/u_string.h | 1 + 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/util/log.h b/src/util/log.h index 7b5c8fd6c20..17670cc97d9 100644 --- a/src/util/log.h +++ b/src/util/log.h @@ -99,7 +99,7 @@ struct log_stream *_mesa_log_stream_create(enum mesa_log_level level, const char #define mesa_log_streamw() _mesa_log_stream_create(MESA_LOG_WARN, (MESA_LOG_TAG)) #define mesa_log_streami() _mesa_log_stream_create(MESA_LOG_INFO, (MESA_LOG_TAG)) void mesa_log_stream_destroy(struct log_stream *stream); -void mesa_log_stream_printf(struct log_stream *stream, const char *format, ...); +void mesa_log_stream_printf(struct log_stream *stream, const char *format, ...) PRINTFLIKE(2, 3); void _mesa_log_multiline(enum mesa_log_level level, const char *tag, const char *lines); #define mesa_log_multiline(level, lines) _mesa_log_multiline(level, (MESA_LOG_TAG), lines) diff --git a/src/util/ralloc.h b/src/util/ralloc.h index 7f6f7e71a7f..5bb0f520147 100644 --- a/src/util/ralloc.h +++ b/src/util/ralloc.h @@ -565,7 +565,7 @@ public: \ * \param parent parent node of the linear allocator * \param size size to allocate (max 32 bits) */ -void *linear_alloc_child(void *parent, unsigned size); +void *linear_alloc_child(void *parent, unsigned size) MALLOCLIKE; /** * Allocate a parent node that will hold linear buffers. The returned @@ -575,17 +575,17 @@ void *linear_alloc_child(void *parent, unsigned size); * \param ralloc_ctx ralloc context, must not be NULL * \param size size to allocate (max 32 bits) */ -void *linear_alloc_parent(void *ralloc_ctx, unsigned size); +void *linear_alloc_parent(void *ralloc_ctx, unsigned size) MALLOCLIKE; /** * Same as linear_alloc_child, but also clears memory. */ -void *linear_zalloc_child(void *parent, unsigned size); +void *linear_zalloc_child(void *parent, unsigned size) MALLOCLIKE; /** * Same as linear_alloc_parent, but also clears memory. */ -void *linear_zalloc_parent(void *ralloc_ctx, unsigned size); +void *linear_zalloc_parent(void *ralloc_ctx, unsigned size) MALLOCLIKE; /** * Free the linear parent node. This will free all child nodes too. @@ -619,7 +619,7 @@ void *linear_realloc(void *parent, void *old, unsigned new_size); * More than a convenience function, this also checks for integer overflow when * multiplying \p size and \p count. This is necessary for security. */ -void *linear_alloc_child_array(void *parent, size_t size, unsigned count); +void *linear_alloc_child_array(void *parent, size_t size, unsigned count) MALLOCLIKE; /** * Do a fast allocation of an array from the linear buffer. @@ -629,19 +629,19 @@ void *linear_alloc_child_array(void *parent, size_t size, unsigned count); * More than a convenience function, this also checks for integer overflow when * multiplying \p size and \p count. This is necessary for security. */ -void *linear_zalloc_child_array(void *parent, size_t size, unsigned count); +void *linear_zalloc_child_array(void *parent, size_t size, unsigned count) MALLOCLIKE; /* The functions below have the same semantics as their ralloc counterparts, * except that they always allocate a linear child node. */ -char *linear_strdup(void *parent, const char *str); -char *linear_asprintf(void *parent, const char *fmt, ...); -char *linear_vasprintf(void *parent, const char *fmt, va_list args); -bool linear_asprintf_append(void *parent, char **str, const char *fmt, ...); +char *linear_strdup(void *parent, const char *str) MALLOCLIKE; +char *linear_asprintf(void *parent, const char *fmt, ...) PRINTFLIKE(2, 3) MALLOCLIKE; +char *linear_vasprintf(void *parent, const char *fmt, va_list args) MALLOCLIKE; +bool linear_asprintf_append(void *parent, char **str, const char *fmt, ...) PRINTFLIKE(3, 4); bool linear_vasprintf_append(void *parent, char **str, const char *fmt, va_list args); bool linear_asprintf_rewrite_tail(void *parent, char **str, size_t *start, - const char *fmt, ...); + const char *fmt, ...) PRINTFLIKE(4, 5); bool linear_vasprintf_rewrite_tail(void *parent, char **str, size_t *start, const char *fmt, va_list args); bool linear_strcat(void *parent, char **dest, const char *str); diff --git a/src/util/string_buffer.h b/src/util/string_buffer.h index eaaf5f33dfd..2cf5a20a61c 100644 --- a/src/util/string_buffer.h +++ b/src/util/string_buffer.h @@ -95,7 +95,7 @@ _mesa_string_buffer_vprintf(struct _mesa_string_buffer *str, bool _mesa_string_buffer_printf(struct _mesa_string_buffer *str, - const char *format, ...); + const char *format, ...) PRINTFLIKE(2, 3); #ifdef __cplusplus } /* extern "C" */ diff --git a/src/util/u_string.h b/src/util/u_string.h index 1ad66e6030a..b9142d7616c 100644 --- a/src/util/u_string.h +++ b/src/util/u_string.h @@ -100,6 +100,7 @@ util_vasprintf(char **ret, const char *format, va_list ap) #define asprintf util_asprintf static inline int + PRINTFLIKE(2, 3) util_asprintf(char **str, const char *fmt, ...) { int ret;