From 22ba40a46689a91f5ccd6c4b5cc0e03ac8032f8f Mon Sep 17 00:00:00 2001 From: jief Date: Thu, 23 Apr 2020 11:23:57 +0300 Subject: [PATCH] Deactivate XStringW operator with native type (to catch things like "Title != NULL") --- rEFIt_UEFI/Platform/Settings.cpp | 4 +-- rEFIt_UEFI/cpp_foundation/XStringW.h | 24 ++++++++-------- .../cpp_unit_test/XStringWArray_test.cpp | 22 +++++++-------- rEFIt_UEFI/cpp_unit_test/XStringW_test.cpp | 28 +++++++++---------- rEFIt_UEFI/entry_scan/loader.cpp | 2 +- 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/rEFIt_UEFI/Platform/Settings.cpp b/rEFIt_UEFI/Platform/Settings.cpp index 5fe8d3f35..22f939f57 100644 --- a/rEFIt_UEFI/Platform/Settings.cpp +++ b/rEFIt_UEFI/Platform/Settings.cpp @@ -861,11 +861,11 @@ CUSTOM_LOADER_ENTRY DuplicateEntry->Options = Entry->Options; - if (Entry->FullTitle != NULL) { + if (Entry->FullTitle.notEmpty()) { DuplicateEntry->FullTitle = Entry->FullTitle; } - if (Entry->Title != NULL) { + if (Entry->Title.notEmpty()) { DuplicateEntry->Title = Entry->Title; } diff --git a/rEFIt_UEFI/cpp_foundation/XStringW.h b/rEFIt_UEFI/cpp_foundation/XStringW.h index 2d612efc1..92b88b771 100755 --- a/rEFIt_UEFI/cpp_foundation/XStringW.h +++ b/rEFIt_UEFI/cpp_foundation/XStringW.h @@ -178,28 +178,28 @@ public: // == operator friend bool operator == (const XStringW& s1, const XStringW& s2) { return s1.Compare(s2._data(0)) == 0; } - friend bool operator == (const XStringW& s1, const wchar_t* s2 ) { return s1.Compare(s2) == 0; } - friend bool operator == (const wchar_t* s1, const XStringW& s2) { return s2.Compare(s1) == 0; } +// friend bool operator == (const XStringW& s1, const wchar_t* s2 ) { return s1.Compare(s2) == 0; } +// friend bool operator == (const wchar_t* s1, const XStringW& s2) { return s2.Compare(s1) == 0; } friend bool operator != (const XStringW& s1, const XStringW& s2) { return s1.Compare(s2._data(0)) != 0; } - friend bool operator != (const XStringW& s1, const wchar_t* s2 ) { return s1.Compare(s2) != 0; } - friend bool operator != (const wchar_t* s1, const XStringW& s2) { return s2.Compare(s1) != 0; } +// friend bool operator != (const XStringW& s1, const wchar_t* s2 ) { return s1.Compare(s2) != 0; } +// friend bool operator != (const wchar_t* s1, const XStringW& s2) { return s2.Compare(s1) != 0; } friend bool operator < (const XStringW& s1, const XStringW& s2) { return s1.Compare(s2._data(0)) < 0; } - friend bool operator < (const XStringW& s1, const wchar_t* s2 ) { return s1.Compare(s2) < 0; } - friend bool operator < (const wchar_t* s1, const XStringW& s2) { return s2.Compare(s1) > 0; } +// friend bool operator < (const XStringW& s1, const wchar_t* s2 ) { return s1.Compare(s2) < 0; } +// friend bool operator < (const wchar_t* s1, const XStringW& s2) { return s2.Compare(s1) > 0; } friend bool operator > (const XStringW& s1, const XStringW& s2) { return s1.Compare(s2._data(0)) > 0; } - friend bool operator > (const XStringW& s1, const wchar_t* s2 ) { return s1.Compare(s2) > 0; } - friend bool operator > (const wchar_t* s1, const XStringW& s2) { return s2.Compare(s1) < 0; } +// friend bool operator > (const XStringW& s1, const wchar_t* s2 ) { return s1.Compare(s2) > 0; } +// friend bool operator > (const wchar_t* s1, const XStringW& s2) { return s2.Compare(s1) < 0; } friend bool operator <= (const XStringW& s1, const XStringW& s2) { return s1.Compare(s2._data(0)) <= 0; } - friend bool operator <= (const XStringW& s1, const wchar_t* s2 ) { return s1.Compare(s2) <= 0; } - friend bool operator <= (const wchar_t* s1, const XStringW& s2) { return s2.Compare(s1) >= 0; } +// friend bool operator <= (const XStringW& s1, const wchar_t* s2 ) { return s1.Compare(s2) <= 0; } +// friend bool operator <= (const wchar_t* s1, const XStringW& s2) { return s2.Compare(s1) >= 0; } friend bool operator >= (const XStringW& s1, const XStringW& s2) { return s1.Compare(s2._data(0)) >= 0; } - friend bool operator >= (const XStringW& s1, const wchar_t* s2 ) { return s1.Compare(s2) >= 0; } - friend bool operator >= (const wchar_t* s1, const XStringW& s2) { return s2.Compare(s1) <= 0; } +// friend bool operator >= (const XStringW& s1, const wchar_t* s2 ) { return s1.Compare(s2) >= 0; } +// friend bool operator >= (const wchar_t* s1, const XStringW& s2) { return s2.Compare(s1) <= 0; } }; diff --git a/rEFIt_UEFI/cpp_unit_test/XStringWArray_test.cpp b/rEFIt_UEFI/cpp_unit_test/XStringWArray_test.cpp index f7b2c3c84..d153f6f61 100644 --- a/rEFIt_UEFI/cpp_unit_test/XStringWArray_test.cpp +++ b/rEFIt_UEFI/cpp_unit_test/XStringWArray_test.cpp @@ -10,16 +10,16 @@ int XStringWArray_tests() #endif XStringWArray array1; - + if ( !array1.IsNull() ) return 1; - + array1.Add(L"1"_XSW); if ( array1.IsNull() ) return 2; array1.Add(L"2"_XSW); - if ( array1[0] != L"1" ) return 3; - if ( array1[1] != L"2" ) return 4; - + if ( array1[0] != L"1"_XSW ) return 3; + if ( array1[1] != L"2"_XSW ) return 4; + if ( !array1.Contains(L"2"_XSW) ) return 5; // Test == and != @@ -27,15 +27,15 @@ int XStringWArray_tests() XStringWArray array1bis; array1bis.Add(L"1"_XSW); array1bis.Add(L"2"_XSW); - + if ( !(array1 == array1bis) ) return 10; if ( array1 != array1bis ) return 11; } - + // Test concat and Split { XStringW c = array1.ConcatAll(L", "_XSW, L"^"_XSW, L"$"_XSW); - if ( c != L"^1, 2$" ) return 1; + if ( c != L"^1, 2$"_XSW ) return 1; // Split doesn't handle prefix and suffix yet. c = array1.ConcatAll(L", "_XSW); @@ -48,13 +48,13 @@ int XStringWArray_tests() array2.Add(L"2"_XSW); array2.Add(L"1"_XSW); - if ( array2[0] != L"2" ) return 30; - if ( array2[1] != L"1" ) return 31; + if ( array2[0] != L"2"_XSW ) return 30; + if ( array2[1] != L"1"_XSW ) return 31; if ( array1 == array2 ) return 40; // Array != because order is different if ( !array1.Same(array2) ) return 41; // Arrays are the same - + array1.AddNoNull(L"3"_XSW); if ( array1.size() != 3 ) return 50; array1.AddNoNull(L""_XSW); diff --git a/rEFIt_UEFI/cpp_unit_test/XStringW_test.cpp b/rEFIt_UEFI/cpp_unit_test/XStringW_test.cpp index 77cf97eac..7fb0f3bdf 100755 --- a/rEFIt_UEFI/cpp_unit_test/XStringW_test.cpp +++ b/rEFIt_UEFI/cpp_unit_test/XStringW_test.cpp @@ -17,8 +17,8 @@ int XStringW_tests() // DebugLog(2, "XStringW_tests -> Enter\n"); #endif - if ( global_str3 != L"global_str3" ) return 1; - if ( global_str4 != L"global_str4" ) return 2; + if ( global_str3 != L"global_str3"_XSW ) return 1; + if ( global_str4 != L"global_str4"_XSW ) return 2; // Check default ctor { @@ -46,9 +46,9 @@ int XStringW_tests() str.takeValueFrom(""); if (str.size() != 0) return 110; str.takeValueFrom("1"); - if ( str != L"1" ) return 111; + if ( str != L"1"_XSW ) return 111; str.StrCat(L"2"); - if ( str != L"12" ) return 112; + if ( str != L"12"_XSW ) return 112; } #endif @@ -86,13 +86,13 @@ int XStringW_tests() XStringW str2; if ( !str2.isEmpty() ) return 10; str2.StrnCpy(str.data(), 2); - if ( str2 != L"12" ) return 11; + if ( str2 != L"12"_XSW ) return 11; str2.StrnCat(L"345", 2); - if ( str2 != L"1234" ) return 12; + if ( str2 != L"1234"_XSW ) return 12; str2.Insert(1, str); - if ( str2 != L"112234" ) return 13; + if ( str2 != L"112234"_XSW ) return 13; str2 += L"6"; - if ( str2 != L"1122346" ) return 14; + if ( str2 != L"1122346"_XSW ) return 14; } //wchar_t c2 = L'Ň'; @@ -100,9 +100,9 @@ int XStringW_tests() //const char* s1 = "𐌾"; XStringW str2; str2.SWPrintf("%c", 'a'); // signle UTF8 ascii char - if ( str2 != L"a" ) return 20; + if ( str2 != L"a"_XSW ) return 20; str2.takeValueFrom(L"ab"); // UTF16(32) string containing ascii char - if ( str2 != L"ab" ) return 21; + if ( str2 != L"ab"_XSW ) return 21; #ifdef _MSC_VER // IMPORTANT : you can't pass a litteral char in a vararg function with Visual Studio (Microsoft strikes again :-). // At least, you got a warning C4066 @@ -123,7 +123,7 @@ int XStringW_tests() if (str2 != s) return 23; #else str2.SWPrintf("%lc", L'Ň'); // signe UTF16(32) char. (2 bytes in total if UTF16) - if ( str2 != L"Ň" ) return 22; + if ( str2 != L"Ň"_XSW ) return 22; str2.takeValueFrom(""); if (str2.size() != 0) return 221; #ifdef XSTRINGW_HAS_CTOR_LITTERAL @@ -148,9 +148,9 @@ int XStringW_tests() // "𐌾" in UTF16 is 2 char : 0xd800, 0xdf3e str2.takeValueFrom(L"𐌾"); // this is a UTF8 string 4 bytes long - if ( str2 != L"𐌾" ) return 31; + if ( str2 != L"𐌾"_XSW ) return 31; str2.takeValueFrom(L"𐌾"); // this is a UTF16 or UTF32 string (depending of -fshort-wchar) - if ( str2 != L"𐌾" ) return 32; + if ( str2 != L"𐌾"_XSW ) return 32; #ifdef XSTRINGW_HAS_CTOR_LITTERAL { @@ -180,7 +180,7 @@ int XStringW_tests() #ifndef _MSC_VER wchar_t* s = XStringW().takeValueFrom("aa").forgetDataWithoutFreeing(); - if ( s != L"aa"_XSW ) return 102; + if ( memcmp(s, L"aa", sizeof(L"aa")*sizeof(wchar_t) ) == 0 ) return 102; // sizeof(L"aa") include null terminator #endif // XStringW CommonName(L"EFI\\CLOVER\\misc\\screenshot"); // for (UINTN Index = 0; Index < 20; Index++) { diff --git a/rEFIt_UEFI/entry_scan/loader.cpp b/rEFIt_UEFI/entry_scan/loader.cpp index 153890d06..641692fd5 100644 --- a/rEFIt_UEFI/entry_scan/loader.cpp +++ b/rEFIt_UEFI/entry_scan/loader.cpp @@ -1991,7 +1991,7 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex, // REFIT_MENU_SCREEN *SubScreen = (__typeof__(SubScreen))AllocateZeroPool(sizeof(REFIT_MENU_SCREEN)); REFIT_MENU_SCREEN *SubScreen = new REFIT_MENU_SCREEN; if (SubScreen) { - SubScreen->Title.SWPrintf("Boot Options for %ls on %ls", (Custom->Title != NULL) ? Custom->Title.wc_str() : CustomPath, Entry->VolName); + SubScreen->Title.SWPrintf("Boot Options for %ls on %ls", (Custom->Title.notEmpty()) ? Custom->Title.wc_str() : CustomPath, Entry->VolName); SubScreen->TitleImage = Entry->Image; SubScreen->ID = Custom->Type + 20; SubScreen->GetAnime();