Skip to content

Commit

Permalink
Release 89: String comparison bug
Browse files Browse the repository at this point in the history
Got the length logic backwards.
  • Loading branch information
SammyB428 committed Aug 4, 2020
1 parent c122b78 commit 4bb8654
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 24 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,12 @@
*.ipch
*.VC.db
*.suo

*.idb
*.ilk
*.iobj
*.ipdb
*.FileListAbsolute.txt
LIB/x64/*
Sample/XMLCheck/x64/*
TEST/Win32_STL_Unicode_Release/*
4 changes: 2 additions & 2 deletions INCLUDE/WFC.H
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@

#define WIN32_FOUNDATION_CLASSES

#define WFC_RELEASE_NUMBER (88)
#define WFC_RELEASE_NUMBER (89)
#if ! defined( WFC_SILENT )
#pragma message( "WFC Release 88." )
#pragma message( "WFC Release 89." )
#endif // WFC_SILENT

#define TAB_CHARACTER (9)
Expand Down
22 changes: 12 additions & 10 deletions INCLUDE/stl_compare.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,11 @@ inline _Check_return_ int compare_no_case(_In_ std::wstring const& s, _In_opt_z_

inline _Check_return_ int compare_no_case(_In_ std::string_view s1, _In_ std::string_view s2) noexcept
{
if (s1.length() < s2.length())
{
return(I_AM_LESS_THAN_THAT);
}

if (s1.length() > s2.length())
{
return(I_AM_GREATER_THAN_THAT);
}
auto const length = std::min(s1.length(), s2.length());

std::size_t index = 0;

while (index < s2.length())
while (index < length)
{
auto const s1_character = std::toupper(s1.at(index));
auto const s2_character = std::toupper(s2.at(index));
Expand All @@ -88,6 +80,16 @@ inline _Check_return_ int compare_no_case(_In_ std::string_view s1, _In_ std::st
index++;
}

if (s1.length() < s2.length())
{
return(I_AM_LESS_THAN_THAT);
}

if (s1.length() > s2.length())
{
return(I_AM_GREATER_THAN_THAT);
}

return(I_AM_EQUAL_TO_THAT);
}

Expand Down
15 changes: 7 additions & 8 deletions INCLUDE/stl_unique.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ inline _Check_return_ SSIZE_T add_to_unique_sorted_vector(_In_ std::string_view

inline _Check_return_ bool compare_strings_ignoring_case(_In_ std::string_view left, _In_ std::string_view right) noexcept
{
return(compare_no_case(left, right) < I_AM_EQUAL_TO_THAT);
return(Win32FoundationClasses::compare_no_case(left, right) < I_AM_EQUAL_TO_THAT);
}

inline _Check_return_ SSIZE_T add_to_unique_sorted_vector_ignore_case(_In_ std::string_view value_to_add, _Inout_ std::vector<std::string>& values) noexcept
{
auto const lower = std::lower_bound(std::cbegin(values), std::cend(values), value_to_add, compare_strings_ignoring_case);
auto const return_value = std::distance(std::cbegin(values), lower);

if (not (lower not_eq std::cend(values) and not (value_to_add < *lower)))
if (not (lower not_eq std::cend(values) and not (compare_strings_ignoring_case(value_to_add, *lower))))
{
values.emplace(lower, value_to_add);
}
Expand All @@ -57,12 +57,12 @@ inline _Check_return_ bool contains_no_case_sorted(_In_ std::vector<std::string>

auto const lower = std::lower_bound(std::cbegin(s), std::cend(s), the_string, compare_strings_ignoring_case);

return (lower not_eq std::cend(s) and (the_string < *lower));
return (lower not_eq std::cend(s) and not (compare_strings_ignoring_case(the_string, *lower)));
}

inline _Check_return_ bool contains(_In_ std::vector<std::string> const& s, _In_z_ char const* the_string) noexcept
inline _Check_return_ bool contains(_In_ std::vector<std::string> const& s, _In_ std::string_view the_string) noexcept
{
if (s.empty() == true or the_string == nullptr)
if (s.empty() == true or the_string.empty() == true)
{
return(false);
}
Expand All @@ -87,7 +87,7 @@ inline _Check_return_ bool contains_no_case(_In_ std::vector<std::wstring> const

for (auto const& entry : s)
{
if (compare_no_case(entry, the_string) == I_AM_EQUAL_TO_THAT)
if (Win32FoundationClasses::compare_no_case(entry, the_string) == I_AM_EQUAL_TO_THAT)
{
return(true);
}
Expand Down Expand Up @@ -123,7 +123,7 @@ inline _Check_return_ bool contains_no_case(_In_ std::vector<std::string> const&

for (auto const& entry : s)
{
if (compare_no_case(entry, the_string) == I_AM_EQUAL_TO_THAT)
if (Win32FoundationClasses::compare_no_case(entry, the_string) == I_AM_EQUAL_TO_THAT)
{
return(true);
}
Expand All @@ -132,7 +132,6 @@ inline _Check_return_ bool contains_no_case(_In_ std::vector<std::string> const&
return(false);
}


inline _Check_return_ bool add_unique(_Inout_ std::vector<std::wstring>& s, _In_ std::wstring_view new_element) noexcept
{
if (contains_no_case(s, new_element) == true)
Expand Down
2 changes: 1 addition & 1 deletion TEST/TEST.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ _Check_return_ int _tmain( _In_ int const number_of_command_line_arguments, _In_
GUID const mlang_class_id = { 0x275c23e2, 0x3747, 0x11d0, 0x9f, 0xea, 0x00, 0xaa, 0x00, 0x3f, 0x86, 0x46 };
GUID const interface_id = { 0xdccfc164, 0x2b38, 0x11d2, 0xb7, 0xec, 0x00, 0xc0, 0x4f, 0x8f, 0x5d, 0x9a };

HRESULT result = CoCreateInstance( mlang_class_id, NULL,
auto result = CoCreateInstance( mlang_class_id, NULL,
CLSCTX_INPROC_SERVER bitor CLSCTX_LOCAL_SERVER,
interface_id,
(LPVOID *) &i );
Expand Down
2 changes: 1 addition & 1 deletion TEST/test_CFile64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ _Check_return_ bool test_CFile64( _Out_ std::string& class_name, _Out_ int& test

for ( auto const loop_index : Range(100) )
{
std::size_t const number_of_characters = sprintf_s( temp_string, sizeof( temp_string ), "Test String %04lu", (unsigned long) loop_index );
std::size_t const number_of_characters = sprintf_s( temp_string, sizeof( temp_string ), "Test String %04zu", loop_index );

if ( strings.at( loop_index ).compare( std::string_view(temp_string, number_of_characters)) not_eq I_AM_EQUAL_TO_THAT )
{
Expand Down
123 changes: 122 additions & 1 deletion TEST/test_CWideString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2228,6 +2228,127 @@ _Check_return_ bool test_CWideString( _Out_ std::string& class_name, _Out_ int&
return(failure());
}

test_number_that_failed = 308;
sorted2.clear();

Win32FoundationClasses::add_to_unique_sorted_vector_ignore_case(STRING_VIEW("keyID"), sorted2);

if (sorted2.size() not_eq 1)
{
test_number_that_failed = 309;
return(failure());
}

if (sorted2.at(0).compare(STRING_VIEW("keyID")) not_eq I_AM_EQUAL_TO_THAT)
{
test_number_that_failed = 310;
return(failure());
}

Win32FoundationClasses::add_to_unique_sorted_vector_ignore_case(STRING_VIEW("locationKey"), sorted2);

if (sorted2.size() not_eq 2)
{
test_number_that_failed = 311;
return(failure());
}

if (sorted2.at(0).compare(STRING_VIEW("keyID")) not_eq I_AM_EQUAL_TO_THAT or
sorted2.at(1).compare(STRING_VIEW("locationKey")) not_eq I_AM_EQUAL_TO_THAT )
{
test_number_that_failed = 312;
return(failure());
}

Win32FoundationClasses::add_to_unique_sorted_vector_ignore_case(STRING_VIEW("typeName"), sorted2);

if (sorted2.size() not_eq 3)
{
test_number_that_failed = 313;
return(failure());
}

if (sorted2.at(0).compare(STRING_VIEW("keyID")) not_eq I_AM_EQUAL_TO_THAT or
sorted2.at(1).compare(STRING_VIEW("locationKey")) not_eq I_AM_EQUAL_TO_THAT or
sorted2.at(2).compare(STRING_VIEW("typeName")) not_eq I_AM_EQUAL_TO_THAT)
{
test_number_that_failed = 314;
return(failure());
}

Win32FoundationClasses::add_to_unique_sorted_vector_ignore_case(STRING_VIEW("uuid"), sorted2);

if (sorted2.size() not_eq 4)
{
test_number_that_failed = 315;
return(failure());
}

if (sorted2.at(0).compare(STRING_VIEW("keyID")) not_eq I_AM_EQUAL_TO_THAT or
sorted2.at(1).compare(STRING_VIEW("locationKey")) not_eq I_AM_EQUAL_TO_THAT or
sorted2.at(2).compare(STRING_VIEW("typeName")) not_eq I_AM_EQUAL_TO_THAT or
sorted2.at(3).compare(STRING_VIEW("uuid")) not_eq I_AM_EQUAL_TO_THAT)
{
test_number_that_failed = 316;
return(failure());
}

Win32FoundationClasses::add_to_unique_sorted_vector_ignore_case(STRING_VIEW("createdAt"), sorted2);

if (sorted2.size() not_eq 5)
{
test_number_that_failed = 317;
return(failure());
}

if (sorted2.at(0).compare(STRING_VIEW("createdAt")) not_eq I_AM_EQUAL_TO_THAT or
sorted2.at(1).compare(STRING_VIEW("keyID")) not_eq I_AM_EQUAL_TO_THAT or
sorted2.at(2).compare(STRING_VIEW("locationKey")) not_eq I_AM_EQUAL_TO_THAT or
sorted2.at(3).compare(STRING_VIEW("typeName")) not_eq I_AM_EQUAL_TO_THAT or
sorted2.at(4).compare(STRING_VIEW("uuid")) not_eq I_AM_EQUAL_TO_THAT)
{
test_number_that_failed = 318;
return(failure());
}

Win32FoundationClasses::add_to_unique_sorted_vector_ignore_case(STRING_VIEW("securityLevel"), sorted2);

if (sorted2.size() not_eq 6)
{
test_number_that_failed = 319;
return(failure());
}

if (sorted2.at(0).compare(STRING_VIEW("createdAt")) not_eq I_AM_EQUAL_TO_THAT or
sorted2.at(1).compare(STRING_VIEW("keyID")) not_eq I_AM_EQUAL_TO_THAT or
sorted2.at(2).compare(STRING_VIEW("locationKey")) not_eq I_AM_EQUAL_TO_THAT or
sorted2.at(3).compare(STRING_VIEW("securityLevel")) not_eq I_AM_EQUAL_TO_THAT or
sorted2.at(4).compare(STRING_VIEW("typeName")) not_eq I_AM_EQUAL_TO_THAT or
sorted2.at(5).compare(STRING_VIEW("uuid")) not_eq I_AM_EQUAL_TO_THAT)
{
test_number_that_failed = 320;
return(failure());
}

Win32FoundationClasses::add_to_unique_sorted_vector_ignore_case(STRING_VIEW("autosubmit"), sorted2);

if (sorted2.size() not_eq 7)
{
test_number_that_failed = 321;
return(failure());
}

if (sorted2.at(0).compare(STRING_VIEW("autosubmit")) not_eq I_AM_EQUAL_TO_THAT or
sorted2.at(1).compare(STRING_VIEW("createdAt")) not_eq I_AM_EQUAL_TO_THAT or
sorted2.at(2).compare(STRING_VIEW("keyID")) not_eq I_AM_EQUAL_TO_THAT or
sorted2.at(3).compare(STRING_VIEW("locationKey")) not_eq I_AM_EQUAL_TO_THAT or
sorted2.at(4).compare(STRING_VIEW("securityLevel")) not_eq I_AM_EQUAL_TO_THAT or
sorted2.at(5).compare(STRING_VIEW("typeName")) not_eq I_AM_EQUAL_TO_THAT or
sorted2.at(6).compare(STRING_VIEW("uuid")) not_eq I_AM_EQUAL_TO_THAT)
{
test_number_that_failed = 322;
return(failure());
}

test_number_that_failed = 322;
return( true );
}
2 changes: 1 addition & 1 deletion ports/wfc/CONTROL
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Source: wfc
Version: 79
Version: 80
Description: Win32 Foundation Classes is a C++ library to help with Win32 programming.

0 comments on commit 4bb8654

Please sign in to comment.