From 6601272e3f5632873d6b186386381f2acd54d4e6 Mon Sep 17 00:00:00 2001 From: Jens Alfke Date: Thu, 5 Dec 2024 10:15:37 -0800 Subject: [PATCH] RefCounted: Resolved a GCC warning Don't ignore the return value (i.e. failure) of asprintf. --- Fleece/Support/RefCounted.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Fleece/Support/RefCounted.cc b/Fleece/Support/RefCounted.cc index 94e8e375..776e6d03 100644 --- a/Fleece/Support/RefCounted.cc +++ b/Fleece/Support/RefCounted.cc @@ -48,10 +48,12 @@ namespace fleece { __cold static void fail(const RefCounted *obj, const char *what, int refCount, bool andThrow =true) { - char *message; - asprintf(&message, + char *message = nullptr; + int n = asprintf(&message, "RefCounted object <%s @ %p> %s while it had an invalid refCount of %d (0x%x)", Unmangle(typeid(*obj)).c_str(), obj, what, refCount, refCount); + if (n < 0) + throw std::runtime_error("RefCounted object has an invalid refCount"); #ifdef WarnError WarnError("%s", message); #else