api: simplify RemoveNumberedSuffix()
Reported-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
f389fd5629
commit
13e90b52cc
@ -421,27 +421,14 @@ GetDevInfoData(_In_ const GUID *CfgInstanceID, _Out_ HDEVINFO *DevInfo, _Out_ SP
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
RemoveNumberedSuffix(_In_z_ const WCHAR *Name, _Out_ WCHAR *Removed)
|
RemoveNumberedSuffix(_Inout_z_ WCHAR *Name)
|
||||||
{
|
{
|
||||||
size_t Len = wcslen(Name);
|
for (size_t i = wcslen(Name); i--;)
|
||||||
if (Len && (Name[Len - 1] < L'0' || Name[Len - 1] > L'9'))
|
|
||||||
{
|
{
|
||||||
wmemcpy(Removed, Name, Len + 1);
|
if ((Name[i] < L'0' || Name[i] > L'9') && !iswspace(Name[i]))
|
||||||
return;
|
return;
|
||||||
|
Name[i] = 0;
|
||||||
}
|
}
|
||||||
for (size_t i = Len; i--;)
|
|
||||||
{
|
|
||||||
if (Name[i] >= L'0' && Name[i] <= L'9')
|
|
||||||
continue;
|
|
||||||
if (Name[i] == L' ')
|
|
||||||
{
|
|
||||||
wmemcpy(Removed, Name, i);
|
|
||||||
Removed[i] = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
wmemcpy(Removed, Name, Len + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -477,8 +464,8 @@ IsPoolMember(
|
|||||||
*IsMember = TRUE;
|
*IsMember = TRUE;
|
||||||
goto cleanupFriendlyName;
|
goto cleanupFriendlyName;
|
||||||
}
|
}
|
||||||
RemoveNumberedSuffix(FriendlyName, FriendlyName);
|
RemoveNumberedSuffix(FriendlyName);
|
||||||
RemoveNumberedSuffix(DeviceDesc, DeviceDesc);
|
RemoveNumberedSuffix(DeviceDesc);
|
||||||
if (!_wcsicmp(FriendlyName, PoolDeviceTypeName) || !_wcsicmp(DeviceDesc, PoolDeviceTypeName))
|
if (!_wcsicmp(FriendlyName, PoolDeviceTypeName) || !_wcsicmp(DeviceDesc, PoolDeviceTypeName))
|
||||||
{
|
{
|
||||||
*IsMember = TRUE;
|
*IsMember = TRUE;
|
||||||
@ -623,7 +610,7 @@ WintunGetAdapter(
|
|||||||
Name2[_countof(Name2) - 1] = 0;
|
Name2[_countof(Name2) - 1] = 0;
|
||||||
if (_wcsicmp(Name, Name2))
|
if (_wcsicmp(Name, Name2))
|
||||||
{
|
{
|
||||||
RemoveNumberedSuffix(Name2, Name2);
|
RemoveNumberedSuffix(Name2);
|
||||||
if (_wcsicmp(Name, Name2))
|
if (_wcsicmp(Name, Name2))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user