From 4dd5e3ea6e3f9290b0a39c09f6bf4b6050291aa9 Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Fri, 13 Mar 2026 08:28:54 -0500 Subject: [PATCH] BUG: Value-initialize singleton instances to avoid indeterminate values The Singleton() template used `new T` (default-initialization) which leaves POD types like bool and unsigned int with indeterminate values. While the itkGetGlobalInitializeMacro immediately assigns the intended value on first creation, the analyzer cannot trace through the singleton index indirection and correctly flags the intermediate indeterminate state. Change to `new T{}` (value-initialization) which zero-initializes POD types, eliminating undefined behavior and resolving: - core.uninitialized.UndefReturn in itkDataObject.cxx:142 - core.uninitialized.UndefReturn in itkObject.cxx:452 - core.uninitialized.UndefReturn in itkMetaImageIO.cxx:940 - core.UndefinedBinaryOperatorResult in itkDataObject.cxx:131 Addresses scan-build findings from issue #1261. Co-Authored-By: Claude Opus 4.6 --- Modules/Core/Common/include/itkSingleton.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/Core/Common/include/itkSingleton.h b/Modules/Core/Common/include/itkSingleton.h index a0847f87323..14b409118a3 100644 --- a/Modules/Core/Common/include/itkSingleton.h +++ b/Modules/Core/Common/include/itkSingleton.h @@ -138,7 +138,7 @@ Singleton(const char * globalName, std::function deleteFunc) T * instance = SingletonIndex::GetInstance()->GetGlobalInstance(globalName); if (instance == nullptr) { - instance = new T; + instance = new T{}; SingletonIndex::GetInstance()->SetGlobalInstance(globalName, instance, std::move(deleteFunc)); } return instance;