From 1b65a150ec6a75b9fca5d7dc88c274bbfb60bd44 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Thu, 28 Apr 2016 14:27:19 +1200 Subject: layers: Fix -Wunused-result warning for vasprintf In case of allocation failure, glibc's vasprintf doesn't make any guarantees about the ptr -- the return value is the only way to handle this safely. Signed-off-by: Chris Forbes --- layers/vk_layer_logging.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/layers/vk_layer_logging.h b/layers/vk_layer_logging.h index 6a3ec01a..424031a4 100644 --- a/layers/vk_layer_logging.h +++ b/layers/vk_layer_logging.h @@ -242,9 +242,13 @@ static inline bool log_msg(debug_report_data *debug_data, VkFlags msgFlags, VkDe va_list argptr; va_start(argptr, format); char *str; - vasprintf(&str, format, argptr); + if (-1 == vasprintf(&str, format, argptr)) { + /* on failure, glibc vasprintf leaves str undefined */ + str = nullptr; + } va_end(argptr); - bool result = debug_report_log_msg(debug_data, msgFlags, objectType, srcObject, location, msgCode, pLayerPrefix, str); + bool result = debug_report_log_msg(debug_data, msgFlags, objectType, srcObject, location, msgCode, pLayerPrefix, + str ? str : "Allocation failure"); free(str); return result; } -- cgit v1.2.3