From 61b05742e64c456436282682a2757774b15f8779 Mon Sep 17 00:00:00 2001 From: cjee21 <77721854+cjee21@users.noreply.github.com> Date: Thu, 30 Jan 2025 20:48:28 +0800 Subject: [PATCH 1/3] Annotate fallthroughs --- Source/ZenLib/BitStream.h | 6 ++++++ Source/ZenLib/BitStream_Fast.h | 6 ++++-- Source/ZenLib/Ztring.cpp | 10 +++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Source/ZenLib/BitStream.h b/Source/ZenLib/BitStream.h index f00e04a0..bccde71c 100644 --- a/Source/ZenLib/BitStream.h +++ b/Source/ZenLib/BitStream.h @@ -98,14 +98,17 @@ class BitStream ToReturn |= ((size_t)*Buffer) << NewBits; Buffer++; Buffer_Size-=8; + [[fallthrough]]; case 2 : NewBits-=8; ToReturn |= ((size_t)*Buffer) << NewBits; Buffer++; Buffer_Size-=8; + [[fallthrough]]; case 1 : NewBits-=8; ToReturn |= ((size_t)*Buffer) << NewBits; Buffer++; Buffer_Size-=8; + [[fallthrough]]; case 0 : LastByte=*Buffer; Buffer++; @@ -191,12 +194,15 @@ class BitStream case 3 : NewBits-=8; Buffer++; Buffer_Size-=8; + [[fallthrough]]; case 2 : NewBits-=8; Buffer++; Buffer_Size-=8; + [[fallthrough]]; case 1 : NewBits-=8; Buffer++; Buffer_Size-=8; + [[fallthrough]]; case 0 : LastByte=*Buffer; Buffer++; diff --git a/Source/ZenLib/BitStream_Fast.h b/Source/ZenLib/BitStream_Fast.h index bbf6f394..2522ba9b 100644 --- a/Source/ZenLib/BitStream_Fast.h +++ b/Source/ZenLib/BitStream_Fast.h @@ -182,11 +182,12 @@ class BitStream_Fast { case 3 : NewBits-=8; ToReturn|=*(Buffer++)<>((Buffer_Size-HowMany)%8))&Mask[NewBits]; diff --git a/Source/ZenLib/Ztring.cpp b/Source/ZenLib/Ztring.cpp index 027a29cc..b871b716 100644 --- a/Source/ZenLib/Ztring.cpp +++ b/Source/ZenLib/Ztring.cpp @@ -1654,23 +1654,23 @@ std::string Ztring::To_UTF8 () const case 6: utf8chars[5] = 0x80 | (wc & 0x3f); wc = (wc >> 6) | 0x4000000; - /* fallthrough */ + [[fallthrough]]; case 5: utf8chars[4] = 0x80 | (wc & 0x3f); wc = (wc >> 6) | 0x200000; - /* fallthrough */ + [[fallthrough]]; case 4: utf8chars[3] = 0x80 | (wc & 0x3f); wc = (wc >> 6) | 0x10000; - /* fallthrough */ + [[fallthrough]]; case 3: utf8chars[2] = 0x80 | (wc & 0x3f); wc = (wc >> 6) | 0x800; - /* fallthrough */ + [[fallthrough]]; case 2: utf8chars[1] = 0x80 | (wc & 0x3f); wc = (wc >> 6) | 0xc0; - /* fallthrough */ + [[fallthrough]]; case 1: utf8chars[0] = (char) wc; } From b045c589d30f237a1d6769392f938dc1ee153417 Mon Sep 17 00:00:00 2001 From: cjee21 <77721854+cjee21@users.noreply.github.com> Date: Thu, 30 Jan 2025 21:39:00 +0800 Subject: [PATCH 2/3] Resolve Visual Studio Code analysis warnings --- Source/ZenLib/BitStream.h | 36 ++++++++++++++++------ Source/ZenLib/BitStream_Fast.h | 16 ++++++---- Source/ZenLib/BitStream_LE.h | 17 +++++----- Source/ZenLib/Dir.cpp | 6 ++-- Source/ZenLib/Format/Http/Http_Cookies.cpp | 5 +-- Source/ZenLib/InfoMap.cpp | 8 ++--- Source/ZenLib/Thread.cpp | 1 + Source/ZenLib/Translation.cpp | 2 +- Source/ZenLib/Ztring.cpp | 16 +++++----- Source/ZenLib/ZtringList.cpp | 4 +-- 10 files changed, 67 insertions(+), 44 deletions(-) diff --git a/Source/ZenLib/BitStream.h b/Source/ZenLib/BitStream.h index bccde71c..e23b8485 100644 --- a/Source/ZenLib/BitStream.h +++ b/Source/ZenLib/BitStream.h @@ -30,16 +30,32 @@ namespace ZenLib class BitStream { public: - BitStream () {Buffer=NULL; - Buffer_Size=Buffer_Size_Init=Buffer_Size_BeforeLastCall=0; - LastByte_Size=0; - BufferUnderRun=true; - BookMark=false;} - BitStream (const int8u* Buffer_, size_t Size_) {Buffer=Buffer_; - Buffer_Size=Buffer_Size_Init=Buffer_Size_BeforeLastCall=Size_*8; //Size is in bits - LastByte_Size=0; - BufferUnderRun=Buffer_Size?false:true; - BookMark=false;} + BitStream () { Buffer = NULL; + Buffer_Size = 0; + Buffer_Size_Init = 0; + Buffer_Size_BeforeLastCall = 0; + LastByte = 0; + LastByte_Size = 0; + BufferUnderRun = true; + BookMark = false; + Buffer_BookMark = 0; + Buffer_Size_BookMark = 0; + LastByte_BookMark = 0; + LastByte_Size_BookMark = 0; + BufferUnderRun_BookMark = false; } + BitStream (const int8u* Buffer_, size_t Size_) { Buffer = Buffer_; + Buffer_Size = Size_ * 8; //Size is in bits + Buffer_Size_Init = Size_ * 8; //Size is in bits + Buffer_Size_BeforeLastCall = Size_ * 8; //Size is in bits + LastByte = 0; + LastByte_Size = 0; + BufferUnderRun = (Buffer_Size ? false : true); + BookMark = false; + Buffer_BookMark = 0; + Buffer_Size_BookMark = 0; + LastByte_BookMark = 0; + LastByte_Size_BookMark = 0; + BufferUnderRun_BookMark = false; } virtual ~BitStream () {}; virtual void Attach(const int8u* Buffer_, size_t Size_) diff --git a/Source/ZenLib/BitStream_Fast.h b/Source/ZenLib/BitStream_Fast.h index 2522ba9b..97063333 100644 --- a/Source/ZenLib/BitStream_Fast.h +++ b/Source/ZenLib/BitStream_Fast.h @@ -30,12 +30,16 @@ namespace ZenLib class BitStream_Fast { public: - BitStream_Fast () {Buffer=NULL; - Buffer_Size=Buffer_Size_Init=0; - BufferUnderRun=false;} - BitStream_Fast (const int8u* Buffer_, size_t Size_) {Buffer=Buffer_; - Buffer_Size=Buffer_Size_Init=Size_*8; //Size is in bits - BufferUnderRun=false;} + BitStream_Fast () { Buffer = NULL; + Buffer_Size = 0; + Buffer_Size_Init = 0; + LastByte = 0; + BufferUnderRun = false; } + BitStream_Fast (const int8u* Buffer_, size_t Size_) { Buffer = Buffer_; + Buffer_Size = Size_ * 8; //Size is in bits + Buffer_Size_Init = Size_ * 8; //Size is in bits + LastByte = 0; + BufferUnderRun = false; } ~BitStream_Fast () {} void Attach(const int8u* Buffer_, size_t Size_) diff --git a/Source/ZenLib/BitStream_LE.h b/Source/ZenLib/BitStream_LE.h index 1a5d63c0..20147c07 100644 --- a/Source/ZenLib/BitStream_LE.h +++ b/Source/ZenLib/BitStream_LE.h @@ -26,16 +26,17 @@ namespace ZenLib class BitStream_LE : public BitStream { public: - BitStream_LE () :BitStream() - { - endbyte=0; - endbit=0; - buffer=NULL; - ptr=NULL; - storage=0; + BitStream_LE() : BitStream(), + endbyte(0), + endbit(0), + buffer(NULL), + ptr(NULL), + ptr_BeforeLastCall(NULL), + storage(0) { }; - BitStream_LE (const int8u* Buffer_, size_t Size_) :BitStream(Buffer_, Size_) { + BitStream_LE (const int8u* Buffer_, size_t Size_) : BitStream(Buffer_, Size_), + ptr_BeforeLastCall(NULL) { Attach(Buffer_, Size_); }; diff --git a/Source/ZenLib/Dir.cpp b/Source/ZenLib/Dir.cpp index 80913112..032a9dff 100644 --- a/Source/ZenLib/Dir.cpp +++ b/Source/ZenLib/Dir.cpp @@ -530,13 +530,13 @@ class GetAllFileNames_Private Dir::dirlist_t Options; HANDLE hFind; #ifdef UNICODE - WIN32_FIND_DATAW FindFileDataW; + WIN32_FIND_DATAW FindFileDataW{}; #else - WIN32_FIND_DATA FindFileData; + WIN32_FIND_DATA FindFileData{}; #endif //UNICODE GetAllFileNames_Private() - : hFind(INVALID_HANDLE_VALUE) + : Options(), hFind(INVALID_HANDLE_VALUE) { } }; diff --git a/Source/ZenLib/Format/Http/Http_Cookies.cpp b/Source/ZenLib/Format/Http/Http_Cookies.cpp index eb416909..207f8eeb 100644 --- a/Source/ZenLib/Format/Http/Http_Cookies.cpp +++ b/Source/ZenLib/Format/Http/Http_Cookies.cpp @@ -100,8 +100,9 @@ void Cookies::Create_Lines(std::ostream& Out) struct tm *Gmt=gmtime(&Cookie->second.Expires); #endif - if (strftime(Temp, 200, "%a, %d-%b-%Y %H:%M:%S GMT", Gmt)) - Out << "; expires=" << Temp; + if (Gmt) + if (strftime(Temp, 200, "%a, %d-%b-%Y %H:%M:%S GMT", Gmt)) + Out << "; expires=" << Temp; } if (!Cookie->second.Path.empty()) { diff --git a/Source/ZenLib/InfoMap.cpp b/Source/ZenLib/InfoMap.cpp index 2741bbb9..d091b2f3 100644 --- a/Source/ZenLib/InfoMap.cpp +++ b/Source/ZenLib/InfoMap.cpp @@ -38,14 +38,14 @@ const Ztring InfoMap_EmptyZtring_Const; //Use it when we can't return a referenc //--------------------------------------------------------------------------- // Constructors InfoMap::InfoMap() -: std::multimap () +: std::multimap (), Max() { Separator[0]=EOL; Separator[1]=__T(";"); } InfoMap::InfoMap(const Ztring &Source) -: std::multimap () +: std::multimap (), Max() { Separator[0]=EOL; Separator[1]=__T(";"); @@ -53,7 +53,7 @@ InfoMap::InfoMap(const Ztring &Source) } InfoMap::InfoMap(const Char *Source) -: std::multimap () +: std::multimap (), Max() { Separator[0]=EOL; Separator[1]=__T(";"); @@ -62,7 +62,7 @@ InfoMap::InfoMap(const Char *Source) #ifdef _UNICODE InfoMap::InfoMap (const char* S) -: std::multimap () +: std::multimap (), Max() { Separator[0]=EOL; Separator[1]=__T(";"); diff --git a/Source/ZenLib/Thread.cpp b/Source/ZenLib/Thread.cpp index f8dde1bd..fd183033 100644 --- a/Source/ZenLib/Thread.cpp +++ b/Source/ZenLib/Thread.cpp @@ -304,6 +304,7 @@ Thread::returnvalue Thread::ForceTerminate() CriticalSectionLocker CSL(C); //Terminating (not clean) + #pragma warning ( suppress : 6258 ) //C6258: Using TerminateThread does not allow proper thread clean up. TerminateThread((HANDLE)ThreadPointer, 1); ThreadPointer=NULL; diff --git a/Source/ZenLib/Translation.cpp b/Source/ZenLib/Translation.cpp index a58a012a..af628cd8 100644 --- a/Source/ZenLib/Translation.cpp +++ b/Source/ZenLib/Translation.cpp @@ -34,7 +34,7 @@ namespace ZenLib //--------------------------------------------------------------------------- // Constructors Translation::Translation() -: std::map () +: std::map (), Max() { Separator[0]=EOL; Separator[1]=__T(";"); diff --git a/Source/ZenLib/Ztring.cpp b/Source/ZenLib/Ztring.cpp index b871b716..1f00638a 100644 --- a/Source/ZenLib/Ztring.cpp +++ b/Source/ZenLib/Ztring.cpp @@ -1867,7 +1867,7 @@ int8s Ztring::To_int8s (int8u Radix, ztring_t Options) const #endif //Rounded - if (Options==Ztring_Rounded && find(__T('.'))!=Error) + if (Options&Ztring_Rounded && find(__T('.'))!=Error) { float80 F=To_float80(); F-=I; @@ -1905,7 +1905,7 @@ int8u Ztring::To_int8u (int8u Radix, ztring_t Options) const #endif //Rounded - if (Options==Ztring_Rounded && find(__T('.'))!=std::string::npos) + if (Options&Ztring_Rounded && find(__T('.'))!=std::string::npos) { float32 F=To_float32(); F-=I; @@ -1943,7 +1943,7 @@ int16s Ztring::To_int16s (int8u Radix, ztring_t Options) const #endif //Rounded - if (Options==Ztring_Rounded && find(__T('.'))!=Error) + if (Options&Ztring_Rounded && find(__T('.'))!=Error) { float80 F=To_float80(); F-=I; @@ -1981,7 +1981,7 @@ int16u Ztring::To_int16u (int8u Radix, ztring_t Options) const #endif //Rounded - if (Options==Ztring_Rounded && find(__T('.'))!=std::string::npos) + if (Options&Ztring_Rounded && find(__T('.'))!=std::string::npos) { float32 F=To_float32(); F-=I; @@ -2019,7 +2019,7 @@ int32s Ztring::To_int32s (int8u Radix, ztring_t Options) const #endif //Rounded - if (Options==Ztring_Rounded && find(__T('.'))!=Error) + if (Options&Ztring_Rounded && find(__T('.'))!=Error) { float80 F=To_float80(); F-=I; @@ -2057,7 +2057,7 @@ int32u Ztring::To_int32u (int8u Radix, ztring_t Options) const #endif //Rounded - if (Options==Ztring_Rounded && find(__T('.'))!=std::string::npos) + if (Options&Ztring_Rounded && find(__T('.'))!=std::string::npos) { float32 F=To_float32(); F-=I; @@ -2095,7 +2095,7 @@ int64s Ztring::To_int64s (int8u Radix, ztring_t Options) const #endif //Rounded - if (Options==Ztring_Rounded && find(__T('.'))!=std::string::npos) + if (Options&Ztring_Rounded && find(__T('.'))!=std::string::npos) { float32 F=To_float32(); F-=I; @@ -2133,7 +2133,7 @@ int64u Ztring::To_int64u (int8u Radix, ztring_t Options) const #endif //Rounded - if (Options==Ztring_Rounded && find(__T('.'))!=std::string::npos) + if (Options&Ztring_Rounded && find(__T('.'))!=std::string::npos) { float32 F=To_float32(); F-=I; diff --git a/Source/ZenLib/ZtringList.cpp b/Source/ZenLib/ZtringList.cpp index 4e960ad1..0e2b5162 100644 --- a/Source/ZenLib/ZtringList.cpp +++ b/Source/ZenLib/ZtringList.cpp @@ -39,7 +39,7 @@ extern Ztring EmptyZtring; //--------------------------------------------------------------------------- // Constructors ZtringList::ZtringList () -: std::vector > () +: std::vector > (), Max() { Separator[0]=__T(";"); Quote=__T("\""); @@ -47,7 +47,7 @@ ZtringList::ZtringList () } ZtringList::ZtringList(const ZtringList &Source) -: std::vector > () +: std::vector > (), Max() { Separator[0]=Source.Separator[0]; Quote=Source.Quote; From ce0edf0fa417b0a94d4bfe014bf0304ba96ae0ed Mon Sep 17 00:00:00 2001 From: cjee21 <77721854+cjee21@users.noreply.github.com> Date: Thu, 30 Jan 2025 21:39:29 +0800 Subject: [PATCH 3/3] Set C++20 standard and Level3 warnings --- Project/MSVC2022/Library/ZenLib.vcxproj | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Project/MSVC2022/Library/ZenLib.vcxproj b/Project/MSVC2022/Library/ZenLib.vcxproj index c798854b..fdca87a2 100644 --- a/Project/MSVC2022/Library/ZenLib.vcxproj +++ b/Project/MSVC2022/Library/ZenLib.vcxproj @@ -160,6 +160,8 @@ ZenLib/PreComp.h true Disabled + stdcpp20 + Level3 @@ -170,6 +172,8 @@ ZenLib/PreComp.h true Disabled + stdcpp20 + Level3 @@ -180,6 +184,8 @@ ZenLib/PreComp.h true Disabled + stdcpp20 + Level3 @@ -190,6 +196,8 @@ ZenLib/PreComp.h true Disabled + stdcpp20 + Level3 @@ -200,7 +208,8 @@ Use ZenLib/PreComp.h Disabled - stdcpplatest + stdcpp20 + Level3 @@ -213,6 +222,8 @@ None NoExtensions Guard + stdcpp20 + Level3 @@ -224,6 +235,8 @@ ZenLib/PreComp.h None Guard + stdcpp20 + Level3 @@ -237,6 +250,8 @@ Guard true true + stdcpp20 + Level3 @@ -250,6 +265,8 @@ Guard true true + stdcpp20 + Level3 @@ -262,6 +279,8 @@ OldStyle Guard true + stdcpp20 + Level3