From 0a01b29005b2cdaccce40818aa795c47a749b3dc Mon Sep 17 00:00:00 2001 From: Filip Filmar Date: Wed, 14 Aug 2019 18:32:43 -0700 Subject: [PATCH] ICU-20776 Checks for nullness in UMutex::lock() Adds `U_ASSERT` check before using `m->lock()` to make allocation issues more apparent at least in debug builds. There is probably quite a few places like this, but let's try fixing broken windows. --- icu4c/source/common/umutex.cpp | 1 + icu4c/source/common/umutex.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/icu4c/source/common/umutex.cpp b/icu4c/source/common/umutex.cpp index 8be43bf960c..fe50d866d4f 100644 --- a/icu4c/source/common/umutex.cpp +++ b/icu4c/source/common/umutex.cpp @@ -98,6 +98,7 @@ std::mutex *UMutex::getMutex() { gListHead = this; } } + U_ASSERT(retPtr != nullptr); return retPtr; } diff --git a/icu4c/source/common/umutex.h b/icu4c/source/common/umutex.h index 13e38b49aae..d154ff84339 100755 --- a/icu4c/source/common/umutex.h +++ b/icu4c/source/common/umutex.h @@ -240,7 +240,8 @@ private: static UMutex *gListHead; /** Out-of-line function to lazily initialize a UMutex on first use. - * Initial fast check is inline, in lock(). + * Initial fast check is inline, in lock(). The returned value may never + * be nullptr. */ std::mutex *getMutex(); };