From 1d6ff6be3c5249f294c52da3199862247a807a95 Mon Sep 17 00:00:00 2001 From: "Marco Antonio J. Costa" Date: Wed, 22 Jul 2026 11:35:59 -0300 Subject: [PATCH] let CIniReader take its strings as pointers to const STR8 is char*, so const STR8 is char* const: a const pointer to a mutable string, which is not what any of these sixty parameters wanted. What they wanted is const CHAR8*, a pointer to a string they will not write to, and that is what all of them do. Under the MSVC compatibility rules clang-cl applies, a string literal still converts to char*, so most calls survive this mistake untouched. An expression of type const char* does not, and Intro.cpp has thirteen of them: inireader.ReadString("INTRO_BEGINNING", "INTRO_REBEL_CRDT", no_defaults ? "" : "INTRO\\Rebel_cr"); The conditional is a const char*, not a literal, so it has nowhere to bind and the call does not compile. The other two arguments are literals and are accepted, which is why only the third one was ever reported. The invariant: in these two files, every parameter spelled const STR8 becomes const CHAR8*, and nothing else changes. No body assigns to one of them, so none needed rewriting; STR8 input_buffer in the five-argument ReadString is genuinely an output and keeps its type. Three commented-out lines still say const STR8 and were left as they are. Verification: grep -n 'const[ \t]*STR8' Utils/INIReader.h Utils/INIReader.cpp # three hits, all on lines beginning with // git show HEAD -U0 | grep '^[+-][^+-]' | sed -E 's/const[ \t]+(STR8|CHAR8\*)/const/g; s/^[+-]//' | sort | uniq -c | awk '$1 % 2' # no output ninja -C build parse # ReadString class gone: 45 -> 32 sites ninja -C build -k 0 # Release, four applications, green ninja -C build-debug -k 0 # Debug, four applications, green Co-Authored-By: Claude Opus 4.8 --- Utils/INIReader.cpp | 30 +++++++++++++++--------------- Utils/INIReader.h | 30 +++++++++++++++--------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Utils/INIReader.cpp b/Utils/INIReader.cpp index 284ec7aa2..be2893b4f 100644 --- a/Utils/INIReader.cpp +++ b/Utils/INIReader.cpp @@ -35,7 +35,7 @@ void CIniReader::RegisterFileForMerging(vfs::Path const& filename) m_merge_files.insert(filename); } -CIniReader::CIniReader(const STR8 szFileName) +CIniReader::CIniReader(const CHAR8* szFileName) { memset(m_szFileName,0,sizeof(m_szFileName)); strncpy(m_szFileName,szFileName, std::min(strlen(szFileName), sizeof(m_szFileName)-1)); @@ -69,7 +69,7 @@ CIniReader::CIniReader(const STR8 szFileName) } } -CIniReader::CIniReader(const STR8 szFileName, BOOLEAN Force_Custom_Data_Path) +CIniReader::CIniReader(const CHAR8* szFileName, BOOLEAN Force_Custom_Data_Path) { memset(m_szFileName,0,sizeof(m_szFileName)); // ary-05/05/2009 : force custom data path for potential non existing file -or- force default data path @@ -105,13 +105,13 @@ void CIniReader::Clear() } -int CIniReader::ReadInteger(const STR8 szSection, const STR8 szKey, int iDefaultValue) +int CIniReader::ReadInteger(const CHAR8* szSection, const CHAR8* szKey, int iDefaultValue) { return (int)(m_oProps.getIntProperty(szSection, szKey, iDefaultValue)); } -int CIniReader::ReadInteger(const STR8 szSection, const STR8 szKey, int defaultValue, int minValue, int maxValue) +int CIniReader::ReadInteger(const CHAR8* szSection, const CHAR8* szKey, int defaultValue, int minValue, int maxValue) { int iniValueReadFromFile = (int)(m_oProps.getIntProperty(szSection, szKey, defaultValue)); //AssertGE(iniValueReadFromFile, minValue); @@ -142,7 +142,7 @@ int CIniReader::ReadInteger(const STR8 szSection, const STR8 szKey, int defaultV // return fltResult; //} -double CIniReader::ReadDouble(const STR8 szSection, const STR8 szKey, double defaultValue, double minValue, double maxValue) +double CIniReader::ReadDouble(const CHAR8* szSection, const CHAR8* szKey, double defaultValue, double minValue, double maxValue) { double iniValueReadFromFile; iniValueReadFromFile = m_oProps.getFloatProperty(szSection, szKey, defaultValue); @@ -161,7 +161,7 @@ double CIniReader::ReadDouble(const STR8 szSection, const STR8 szKey, double def return iniValueReadFromFile; } -FLOAT CIniReader::ReadFloat(const STR8 szSection, const STR8 szKey, FLOAT defaultValue, FLOAT minValue, FLOAT maxValue) +FLOAT CIniReader::ReadFloat(const CHAR8* szSection, const CHAR8* szKey, FLOAT defaultValue, FLOAT minValue, FLOAT maxValue) { FLOAT iniValueReadFromFile; iniValueReadFromFile = (FLOAT) m_oProps.getFloatProperty(szSection, szKey, (float)defaultValue); @@ -182,7 +182,7 @@ FLOAT CIniReader::ReadFloat(const STR8 szSection, const STR8 szKey, FLOAT defaul return iniValueReadFromFile; } -void CIniReader::ReadFloatArray(const STR8 szSection, const STR8 szKey, std::vector& vec) +void CIniReader::ReadFloatArray(const CHAR8* szSection, const CHAR8* szKey, std::vector& vec) { // read the array as a string STRING512 textBuffer; @@ -219,7 +219,7 @@ void CIniReader::ReadFloatArray(const STR8 szSection, const STR8 szKey, std::vec } } -void CIniReader::ReadINT32Array(const STR8 szSection, const STR8 szKey, std::vector& vec) +void CIniReader::ReadINT32Array(const CHAR8* szSection, const CHAR8* szKey, std::vector& vec) { // read the array as a string STRING512 textBuffer; @@ -256,7 +256,7 @@ void CIniReader::ReadINT32Array(const STR8 szSection, const STR8 szKey, std::vec } } -BOOLEAN CIniReader::ReadBoolean(const STR8 szSection, const STR8 szKey, bool defaultValue, bool bolDisplayError) +BOOLEAN CIniReader::ReadBoolean(const CHAR8* szSection, const CHAR8* szKey, bool defaultValue, bool bolDisplayError) { vfs::String str = m_oProps.getStringProperty(szSection, szKey, L""); if( vfs::StrCmp::Equal(str, L"true") ) @@ -285,7 +285,7 @@ BOOLEAN CIniReader::ReadBoolean(const STR8 szSection, const STR8 szKey, bool def // memset(test_ini_string, 0x00, 255); // iniReader.ReadString("JA2 Game Settings" , "TEST_STRING" , "default string" , test_ini_string , 255 ); -void CIniReader::ReadString(const STR8 szSection, const STR8 szKey, const STR8 szDefaultValue, STR8 input_buffer, size_t buffer_size) +void CIniReader::ReadString(const CHAR8* szSection, const CHAR8* szKey, const CHAR8* szDefaultValue, STR8 input_buffer, size_t buffer_size) { std::string s = m_oProps.getStringProperty(szSection, szKey, szDefaultValue).utf8(); int len = std::min(s.length(),buffer_size-1); @@ -294,7 +294,7 @@ void CIniReader::ReadString(const STR8 szSection, const STR8 szKey, const STR8 s } // WANNE - MP: Old version, currently used by Multiplayer -STR8 CIniReader::ReadString(const STR8 szSection, const STR8 szKey, const STR8 szDefaultValue) +STR8 CIniReader::ReadString(const CHAR8* szSection, const CHAR8* szKey, const CHAR8* szDefaultValue) { // >>>>> Memory Leak <<<<< STR8 szResult = new char[255]; @@ -304,7 +304,7 @@ STR8 CIniReader::ReadString(const STR8 szSection, const STR8 szKey, const STR8 s return szResult; } -UINT8 CIniReader::ReadUINT8(const STR8 szSection, const STR8 szKey, UINT8 defaultValue, UINT8 minValue, UINT8 maxValue) +UINT8 CIniReader::ReadUINT8(const CHAR8* szSection, const CHAR8* szKey, UINT8 defaultValue, UINT8 minValue, UINT8 maxValue) { UINT8 iniValueReadFromFile; @@ -315,7 +315,7 @@ UINT8 CIniReader::ReadUINT8(const STR8 szSection, const STR8 szKey, UINT8 defa } -UINT16 CIniReader::ReadUINT16(const STR8 szSection, const STR8 szKey, UINT16 defaultValue, UINT16 minValue, UINT16 maxValue) +UINT16 CIniReader::ReadUINT16(const CHAR8* szSection, const CHAR8* szKey, UINT16 defaultValue, UINT16 minValue, UINT16 maxValue) { UINT16 iniValueReadFromFile; @@ -325,7 +325,7 @@ UINT16 CIniReader::ReadUINT16(const STR8 szSection, const STR8 szKey, UINT16 def } -UINT32 CIniReader::ReadUINT32(const STR8 szSection, const STR8 szKey, UINT32 defaultValue, UINT32 minValue, UINT32 maxValue) +UINT32 CIniReader::ReadUINT32(const CHAR8* szSection, const CHAR8* szKey, UINT32 defaultValue, UINT32 minValue, UINT32 maxValue) { UINT32 iniValueReadFromFile; @@ -335,7 +335,7 @@ UINT32 CIniReader::ReadUINT32(const STR8 szSection, const STR8 szKey, UINT32 def } -UINT32 CIniReader::ReadUINT(const STR8 szSection, const STR8 szKey, UINT32 defaultValue, UINT32 minValue, UINT32 maxValue ) +UINT32 CIniReader::ReadUINT(const CHAR8* szSection, const CHAR8* szKey, UINT32 defaultValue, UINT32 minValue, UINT32 maxValue ) { UINT32 iniValueReadFromFile; iniValueReadFromFile = (UINT32) m_oProps.getUIntProperty(szSection, szKey, defaultValue); diff --git a/Utils/INIReader.h b/Utils/INIReader.h index 1454d8b95..440d2868c 100644 --- a/Utils/INIReader.h +++ b/Utils/INIReader.h @@ -23,35 +23,35 @@ extern std::stack iniErrorMessages; class CIniReader { public: - CIniReader(const STR8 szFileName); - CIniReader(const STR8 szFileName, BOOLEAN Force_Custom_Data_Path); // force path for nonexisting INI files + CIniReader(const CHAR8* szFileName); + CIniReader(const CHAR8* szFileName, BOOLEAN Force_Custom_Data_Path); // force path for nonexisting INI files // Warning: the following function will be removed - int ReadInteger(const STR8 szSection, const STR8 szKey, int iDefaultValue); - int ReadInteger(const STR8 szSection, const STR8 szKey, int defaultValue, int minValue, int maxValue); + int ReadInteger(const CHAR8* szSection, const CHAR8* szKey, int iDefaultValue); + int ReadInteger(const CHAR8* szSection, const CHAR8* szKey, int defaultValue, int minValue, int maxValue); //UINT32 CIniReader::testReadUINT32(void);//various limit tests of UINT and double/float handling //front end functions that control type interpretation and range control, each calls internal ReadUINT - UINT32 ReadUINT32(const STR8 szSection, const STR8 szKey, UINT32 defaultValue, UINT32 minValue, UINT32 maxValue); - UINT16 ReadUINT16(const STR8 szSection, const STR8 szKey, UINT16 defaultValue, UINT16 minValue, UINT16 maxValue); - UINT8 ReadUINT8 (const STR8 szSection, const STR8 szKey, UINT8 defaultValue, UINT8 minValue, UINT8 maxValue); + UINT32 ReadUINT32(const CHAR8* szSection, const CHAR8* szKey, UINT32 defaultValue, UINT32 minValue, UINT32 maxValue); + UINT16 ReadUINT16(const CHAR8* szSection, const CHAR8* szKey, UINT16 defaultValue, UINT16 minValue, UINT16 maxValue); + UINT8 ReadUINT8 (const CHAR8* szSection, const CHAR8* szKey, UINT8 defaultValue, UINT8 minValue, UINT8 maxValue); // Warning: the following function will be removed //double ReadDouble(const STR8 szSection, const STR8 szKey, double fltDefaultValue); // Read_reals - DOUBLE ReadDouble(const STR8 szSection, const STR8 szKey, DOUBLE defaultValue, DOUBLE minValue, DOUBLE maxValue); - FLOAT ReadFloat (const STR8 szSection, const STR8 szKey, FLOAT defaultValue, FLOAT minValue, FLOAT maxValue); + DOUBLE ReadDouble(const CHAR8* szSection, const CHAR8* szKey, DOUBLE defaultValue, DOUBLE minValue, DOUBLE maxValue); + FLOAT ReadFloat (const CHAR8* szSection, const CHAR8* szKey, FLOAT defaultValue, FLOAT minValue, FLOAT maxValue); - void ReadFloatArray(const STR8 szSection, const STR8 szKey, std::vector& vec); - void ReadINT32Array(const STR8 szSection, const STR8 szKey, std::vector& vec); + void ReadFloatArray(const CHAR8* szSection, const CHAR8* szKey, std::vector& vec); + void ReadINT32Array(const CHAR8* szSection, const CHAR8* szKey, std::vector& vec); - BOOLEAN ReadBoolean(const STR8 szSection, const STR8 szKey, bool bolDefaultValue, bool bolDisplayError = true); + BOOLEAN ReadBoolean(const CHAR8* szSection, const CHAR8* szKey, bool bolDefaultValue, bool bolDisplayError = true); - void ReadString(const STR8 szSection, const STR8 szKey, const STR8 szDefaultValue, STR8 input_buffer, size_t buffer_size); + void ReadString(const CHAR8* szSection, const CHAR8* szKey, const CHAR8* szDefaultValue, STR8 input_buffer, size_t buffer_size); // WANNE - MP: Old version, currently used by Multiplayer - STR8 ReadString(const STR8 szSection, const STR8 szKey, const STR8 szDefaultValue); + STR8 ReadString(const CHAR8* szSection, const CHAR8* szKey, const CHAR8* szDefaultValue); BOOLEAN Is_CIniReader_File_Found(void) {return (CIniReader_File_Found);} void Clear(); @@ -62,7 +62,7 @@ private: char m_szFileName[MAX_PATH]; BOOLEAN CIniReader_File_Found; - UINT32 ReadUINT(const STR8 szSection, const STR8 szKey, UINT32 defaultValue, UINT32 minValue, UINT32 maxValue); + UINT32 ReadUINT(const CHAR8* szSection, const CHAR8* szKey, UINT32 defaultValue, UINT32 minValue, UINT32 maxValue); static std::set m_merge_files; };