util: Add more PRINTFLIKE and MALLOCLIKE annotations

Reviewed-by: Yonggang Luo <luoyonggang@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25230>
This commit is contained in:
Caio Oliveira
2023-09-14 08:22:57 -07:00
parent 931253b45d
commit ae99a3d76c
4 changed files with 14 additions and 13 deletions

View File

@@ -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)

View File

@@ -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);

View File

@@ -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" */

View File

@@ -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;