From 892fa0bb880ce84ff09191a5b12a718cfebb2739 Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Sun, 13 Jul 2025 14:24:35 +1000 Subject: [PATCH] fileapi: Use unsigned int consistently for version numbers The file API code used unsigned long to hold the major version in most places, but not all. Some places used unsigned int, and an important one of those is the cmFileApi::BuildVersion() function. As a result, it has never been safe for a large value not representable by an unsigned int to be used in these variables. Convert all of the file API version number variables and function arguments to use unsigned int consistently. This avoids any size mismatch warnings when passing values around. They also don't need to be unsigned long, as we never expect version numbers to be anything even close to what an unsigned int cannot represent. --- Source/cmConfigureLog.cxx | 6 +++--- Source/cmConfigureLog.h | 6 +++--- Source/cmFileAPI.cxx | 6 +++--- Source/cmFileAPI.h | 4 ++-- Source/cmFileAPICMakeFiles.cxx | 8 ++++---- Source/cmFileAPICMakeFiles.h | 2 +- Source/cmFileAPICache.cxx | 8 ++++---- Source/cmFileAPICache.h | 2 +- Source/cmFileAPICodemodel.cxx | 14 +++++++------- Source/cmFileAPICodemodel.h | 2 +- Source/cmFileAPIConfigureLog.cxx | 9 ++++----- Source/cmFileAPIConfigureLog.h | 2 +- Source/cmFileAPIToolchains.cxx | 8 ++++---- Source/cmFileAPIToolchains.h | 2 +- Source/cmMessageCommand.cxx | 2 +- Source/cmTryCompileCommand.cxx | 2 +- Source/cmTryRunCommand.cxx | 2 +- 17 files changed, 42 insertions(+), 43 deletions(-) diff --git a/Source/cmConfigureLog.cxx b/Source/cmConfigureLog.cxx index b486cc3df3..5f0c3c66dd 100644 --- a/Source/cmConfigureLog.cxx +++ b/Source/cmConfigureLog.cxx @@ -23,12 +23,12 @@ #include "cmake.h" cmConfigureLog::cmConfigureLog(std::string logDir, - std::vector logVersions) + std::vector logVersions) : LogDir(std::move(logDir)) , LogVersions(std::move(logVersions)) { // Always emit events for the latest log version. - static unsigned long const LatestLogVersion = 1; + static unsigned int const LatestLogVersion = 1; if (!cm::contains(this->LogVersions, LatestLogVersion)) { this->LogVersions.emplace_back(LatestLogVersion); } @@ -46,7 +46,7 @@ cmConfigureLog::~cmConfigureLog() } bool cmConfigureLog::IsAnyLogVersionEnabled( - std::vector const& v) const + std::vector const& v) const { // Both input lists are sorted. Look for a matching element. auto i1 = v.cbegin(); diff --git a/Source/cmConfigureLog.h b/Source/cmConfigureLog.h index 6c6c44f40f..a48504151f 100644 --- a/Source/cmConfigureLog.h +++ b/Source/cmConfigureLog.h @@ -22,12 +22,12 @@ class cmConfigureLog public: /** Construct with the log directory and a sorted list of enabled log versions. The latest log version will be enabled regardless. */ - cmConfigureLog(std::string logDir, std::vector logVersions); + cmConfigureLog(std::string logDir, std::vector logVersions); ~cmConfigureLog(); /** Return true if at least one of the log versions in the given sorted list is enabled. */ - bool IsAnyLogVersionEnabled(std::vector const& v) const; + bool IsAnyLogVersionEnabled(std::vector const& v) const; void EnsureInit(); @@ -60,7 +60,7 @@ public: private: std::string LogDir; - std::vector LogVersions; + std::vector LogVersions; cmsys::ofstream Stream; unsigned Indent = 0; bool Opened = false; diff --git a/Source/cmFileAPI.cxx b/Source/cmFileAPI.cxx index 6ae22db5c3..d9f484f603 100644 --- a/Source/cmFileAPI.cxx +++ b/Source/cmFileAPI.cxx @@ -85,9 +85,9 @@ void cmFileAPI::ReadQueries() } } -std::vector cmFileAPI::GetConfigureLogVersions() +std::vector cmFileAPI::GetConfigureLogVersions() { - std::vector versions; + std::vector versions; auto getConfigureLogVersions = [&versions](Query const& q) { for (Object const& o : q.Known) { if (o.Kind == ObjectKind::ConfigureLog) { @@ -126,7 +126,7 @@ std::vector cmFileAPI::LoadDir(std::string const& dir) std::vector files; cmsys::Directory d; d.Load(dir); - for (unsigned long i = 0; i < d.GetNumberOfFiles(); ++i) { + for (unsigned int i = 0; i < d.GetNumberOfFiles(); ++i) { std::string f = d.GetFile(i); if (f != "." && f != "..") { files.push_back(std::move(f)); diff --git a/Source/cmFileAPI.h b/Source/cmFileAPI.h index 5b639ced44..d847e8b2a2 100644 --- a/Source/cmFileAPI.h +++ b/Source/cmFileAPI.h @@ -25,7 +25,7 @@ public: void ReadQueries(); /** Get the list of configureLog object kind versions requested. */ - std::vector GetConfigureLogVersions(); + std::vector GetConfigureLogVersions(); /** Identify the situation in which WriteReplies is called. */ enum class IndexFor @@ -83,7 +83,7 @@ private: struct Object { ObjectKind Kind; - unsigned long Version = 0; + unsigned int Version = 0; friend bool operator<(Object const& l, Object const& r) { if (l.Kind != r.Kind) { diff --git a/Source/cmFileAPICMakeFiles.cxx b/Source/cmFileAPICMakeFiles.cxx index 68c13e80dc..2bb2083995 100644 --- a/Source/cmFileAPICMakeFiles.cxx +++ b/Source/cmFileAPICMakeFiles.cxx @@ -22,7 +22,7 @@ namespace { class CMakeFiles { cmFileAPI& FileAPI; - unsigned long Version; + unsigned int Version; std::string CMakeModules; std::string const& TopSource; std::string const& TopBuild; @@ -35,11 +35,11 @@ class CMakeFiles Json::Value DumpGlobDependent(cmGlobCacheEntry const& entry); public: - CMakeFiles(cmFileAPI& fileAPI, unsigned long version); + CMakeFiles(cmFileAPI& fileAPI, unsigned int version); Json::Value Dump(); }; -CMakeFiles::CMakeFiles(cmFileAPI& fileAPI, unsigned long version) +CMakeFiles::CMakeFiles(cmFileAPI& fileAPI, unsigned int version) : FileAPI(fileAPI) , Version(version) , CMakeModules(cmSystemTools::GetCMakeRoot() + "/Modules") @@ -150,7 +150,7 @@ Json::Value CMakeFiles::DumpGlobDependent(cmGlobCacheEntry const& entry) } } -Json::Value cmFileAPICMakeFilesDump(cmFileAPI& fileAPI, unsigned long version) +Json::Value cmFileAPICMakeFilesDump(cmFileAPI& fileAPI, unsigned int version) { CMakeFiles cmakeFiles(fileAPI, version); return cmakeFiles.Dump(); diff --git a/Source/cmFileAPICMakeFiles.h b/Source/cmFileAPICMakeFiles.h index 06f6ff502f..8e15f8ee72 100644 --- a/Source/cmFileAPICMakeFiles.h +++ b/Source/cmFileAPICMakeFiles.h @@ -9,4 +9,4 @@ class cmFileAPI; extern Json::Value cmFileAPICMakeFilesDump(cmFileAPI& fileAPI, - unsigned long version); + unsigned int version); diff --git a/Source/cmFileAPICache.cxx b/Source/cmFileAPICache.cxx index 74b3aa5a6b..10be5a129d 100644 --- a/Source/cmFileAPICache.cxx +++ b/Source/cmFileAPICache.cxx @@ -19,7 +19,7 @@ namespace { class Cache { cmFileAPI& FileAPI; - unsigned long Version; + unsigned int Version; cmState* State; Json::Value DumpEntries(); @@ -29,11 +29,11 @@ class Cache std::string const& prop); public: - Cache(cmFileAPI& fileAPI, unsigned long version); + Cache(cmFileAPI& fileAPI, unsigned int version); Json::Value Dump(); }; -Cache::Cache(cmFileAPI& fileAPI, unsigned long version) +Cache::Cache(cmFileAPI& fileAPI, unsigned int version) : FileAPI(fileAPI) , Version(version) , State(this->FileAPI.GetCMakeInstance()->GetState()) @@ -101,7 +101,7 @@ Json::Value Cache::DumpEntryProperty(std::string const& name, } } -Json::Value cmFileAPICacheDump(cmFileAPI& fileAPI, unsigned long version) +Json::Value cmFileAPICacheDump(cmFileAPI& fileAPI, unsigned int version) { Cache cache(fileAPI, version); return cache.Dump(); diff --git a/Source/cmFileAPICache.h b/Source/cmFileAPICache.h index dc179fa2b8..d480cc2cb9 100644 --- a/Source/cmFileAPICache.h +++ b/Source/cmFileAPICache.h @@ -9,4 +9,4 @@ class cmFileAPI; extern Json::Value cmFileAPICacheDump(cmFileAPI& fileAPI, - unsigned long version); + unsigned int version); diff --git a/Source/cmFileAPICodemodel.cxx b/Source/cmFileAPICodemodel.cxx index 3d6041211f..5b61105254 100644 --- a/Source/cmFileAPICodemodel.cxx +++ b/Source/cmFileAPICodemodel.cxx @@ -223,21 +223,21 @@ Json::Value BacktraceData::Dump() class Codemodel { cmFileAPI& FileAPI; - unsigned long Version; + unsigned int Version; Json::Value DumpPaths(); Json::Value DumpConfigurations(); Json::Value DumpConfiguration(std::string const& config); public: - Codemodel(cmFileAPI& fileAPI, unsigned long version); + Codemodel(cmFileAPI& fileAPI, unsigned int version); Json::Value Dump(); }; class CodemodelConfig { cmFileAPI& FileAPI; - unsigned long Version; + unsigned int Version; std::string const& Config; std::string TopSource; std::string TopBuild; @@ -290,7 +290,7 @@ class CodemodelConfig Json::Value DumpMinimumCMakeVersion(cmStateSnapshot s); public: - CodemodelConfig(cmFileAPI& fileAPI, unsigned long version, + CodemodelConfig(cmFileAPI& fileAPI, unsigned int version, std::string const& config); Json::Value Dump(); }; @@ -515,7 +515,7 @@ public: Json::Value Dump(); }; -Codemodel::Codemodel(cmFileAPI& fileAPI, unsigned long version) +Codemodel::Codemodel(cmFileAPI& fileAPI, unsigned int version) : FileAPI(fileAPI) , Version(version) { @@ -561,7 +561,7 @@ Json::Value Codemodel::DumpConfiguration(std::string const& config) return configuration.Dump(); } -CodemodelConfig::CodemodelConfig(cmFileAPI& fileAPI, unsigned long version, +CodemodelConfig::CodemodelConfig(cmFileAPI& fileAPI, unsigned int version, std::string const& config) : FileAPI(fileAPI) , Version(version) @@ -2154,7 +2154,7 @@ Json::Value Target::DumpDebugger() return debuggerInformation; } -Json::Value cmFileAPICodemodelDump(cmFileAPI& fileAPI, unsigned long version) +Json::Value cmFileAPICodemodelDump(cmFileAPI& fileAPI, unsigned int version) { Codemodel codemodel(fileAPI, version); return codemodel.Dump(); diff --git a/Source/cmFileAPICodemodel.h b/Source/cmFileAPICodemodel.h index 6a3d7b2759..de74d7f80e 100644 --- a/Source/cmFileAPICodemodel.h +++ b/Source/cmFileAPICodemodel.h @@ -9,4 +9,4 @@ class cmFileAPI; extern Json::Value cmFileAPICodemodelDump(cmFileAPI& fileAPI, - unsigned long version); + unsigned int version); diff --git a/Source/cmFileAPIConfigureLog.cxx b/Source/cmFileAPIConfigureLog.cxx index 3e5ba94350..7cd3d97dac 100644 --- a/Source/cmFileAPIConfigureLog.cxx +++ b/Source/cmFileAPIConfigureLog.cxx @@ -13,17 +13,17 @@ namespace { class ConfigureLog { cmFileAPI& FileAPI; - unsigned long Version; + unsigned int Version; Json::Value DumpPath(); Json::Value DumpEventKindNames(); public: - ConfigureLog(cmFileAPI& fileAPI, unsigned long version); + ConfigureLog(cmFileAPI& fileAPI, unsigned int version); Json::Value Dump(); }; -ConfigureLog::ConfigureLog(cmFileAPI& fileAPI, unsigned long version) +ConfigureLog::ConfigureLog(cmFileAPI& fileAPI, unsigned int version) : FileAPI(fileAPI) , Version(version) { @@ -62,8 +62,7 @@ Json::Value ConfigureLog::DumpEventKindNames() } } -Json::Value cmFileAPIConfigureLogDump(cmFileAPI& fileAPI, - unsigned long version) +Json::Value cmFileAPIConfigureLogDump(cmFileAPI& fileAPI, unsigned int version) { ConfigureLog configureLog(fileAPI, version); return configureLog.Dump(); diff --git a/Source/cmFileAPIConfigureLog.h b/Source/cmFileAPIConfigureLog.h index b290828a64..b1da1f8c8d 100644 --- a/Source/cmFileAPIConfigureLog.h +++ b/Source/cmFileAPIConfigureLog.h @@ -9,4 +9,4 @@ class cmFileAPI; extern Json::Value cmFileAPIConfigureLogDump(cmFileAPI& fileAPI, - unsigned long version); + unsigned int version); diff --git a/Source/cmFileAPIToolchains.cxx b/Source/cmFileAPIToolchains.cxx index 74d69bf2ee..c156ca164e 100644 --- a/Source/cmFileAPIToolchains.cxx +++ b/Source/cmFileAPIToolchains.cxx @@ -29,7 +29,7 @@ struct ToolchainVariable class Toolchains { cmFileAPI& FileAPI; - unsigned long Version; + unsigned int Version; Json::Value DumpToolchains(); Json::Value DumpToolchain(std::string const& lang); @@ -41,11 +41,11 @@ class Toolchains ToolchainVariable const& variable); public: - Toolchains(cmFileAPI& fileAPI, unsigned long version); + Toolchains(cmFileAPI& fileAPI, unsigned int version); Json::Value Dump(); }; -Toolchains::Toolchains(cmFileAPI& fileAPI, unsigned long version) +Toolchains::Toolchains(cmFileAPI& fileAPI, unsigned int version) : FileAPI(fileAPI) , Version(version) { @@ -143,7 +143,7 @@ void Toolchains::DumpToolchainVariable(cmMakefile const* mf, } } -Json::Value cmFileAPIToolchainsDump(cmFileAPI& fileAPI, unsigned long version) +Json::Value cmFileAPIToolchainsDump(cmFileAPI& fileAPI, unsigned int version) { Toolchains toolchains(fileAPI, version); return toolchains.Dump(); diff --git a/Source/cmFileAPIToolchains.h b/Source/cmFileAPIToolchains.h index b6b48fbc0f..b7676a873c 100644 --- a/Source/cmFileAPIToolchains.h +++ b/Source/cmFileAPIToolchains.h @@ -9,4 +9,4 @@ class cmFileAPI; extern Json::Value cmFileAPIToolchainsDump(cmFileAPI& fileAPI, - unsigned long version); + unsigned int version); diff --git a/Source/cmMessageCommand.cxx b/Source/cmMessageCommand.cxx index 34092b3248..e19f4ef8a2 100644 --- a/Source/cmMessageCommand.cxx +++ b/Source/cmMessageCommand.cxx @@ -69,7 +69,7 @@ void WriteMessageEvent(cmConfigureLog& log, cmMakefile const& mf, std::string const& message) { // Keep in sync with cmFileAPIConfigureLog's DumpEventKindNames. - static std::vector const LogVersionsWithMessageV1{ 1 }; + static std::vector const LogVersionsWithMessageV1{ 1 }; if (log.IsAnyLogVersionEnabled(LogVersionsWithMessageV1)) { log.BeginEvent("message-v1", mf); diff --git a/Source/cmTryCompileCommand.cxx b/Source/cmTryCompileCommand.cxx index 9f42769458..40d3d8a18e 100644 --- a/Source/cmTryCompileCommand.cxx +++ b/Source/cmTryCompileCommand.cxx @@ -22,7 +22,7 @@ void WriteTryCompileEvent(cmConfigureLog& log, cmMakefile const& mf, cmTryCompileResult const& compileResult) { // Keep in sync with cmFileAPIConfigureLog's DumpEventKindNames. - static std::vector const LogVersionsWithTryCompileV1{ 1 }; + static std::vector const LogVersionsWithTryCompileV1{ 1 }; if (log.IsAnyLogVersionEnabled(LogVersionsWithTryCompileV1)) { log.BeginEvent("try_compile-v1", mf); diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index f6436c60dc..0889ff0f87 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -41,7 +41,7 @@ void WriteTryRunEvent(cmConfigureLog& log, cmMakefile const& mf, cmTryRunResult const& runResult) { // Keep in sync with cmFileAPIConfigureLog's DumpEventKindNames. - static std::vector const LogVersionsWithTryRunV1{ 1 }; + static std::vector const LogVersionsWithTryRunV1{ 1 }; if (log.IsAnyLogVersionEnabled(LogVersionsWithTryRunV1)) { log.BeginEvent("try_run-v1", mf);