Zebediah Figura : quartz: Simplify error handling in process_pattern_string().
Alexandre Julliard
julliard at winehq.org
Wed Aug 7 15:36:22 CDT 2019
Module: wine
Branch: master
Commit: 4555da1d7f3a64d5bb2ebf0c37c04271b003a8a2
URL: https://source.winehq.org/git/wine.git/?a=commit;h=4555da1d7f3a64d5bb2ebf0c37c04271b003a8a2
Author: Zebediah Figura <z.figura12 at gmail.com>
Date: Tue Aug 6 14:58:34 2019 -0500
quartz: Simplify error handling in process_pattern_string().
Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/quartz/filesource.c | 126 ++++++++++++++++++++++-------------------------
1 file changed, 58 insertions(+), 68 deletions(-)
diff --git a/dlls/quartz/filesource.c b/dlls/quartz/filesource.c
index d547c12..f3d9cd4 100644
--- a/dlls/quartz/filesource.c
+++ b/dlls/quartz/filesource.c
@@ -129,94 +129,84 @@ static unsigned char byte_from_hex_char(WCHAR wHex)
}
}
-static HRESULT process_pattern_string(LPCWSTR wszPatternString, IAsyncReader * pReader)
+static BOOL process_pattern_string(const WCHAR *pattern, IAsyncReader *reader)
{
- ULONG ulOffset;
- ULONG ulBytes;
- BYTE * pbMask;
- BYTE * pbValue;
- BYTE * pbFile;
- HRESULT hr = S_OK;
- ULONG strpos;
-
- /* format: "offset, bytestocompare, mask, value" */
-
- ulOffset = wcstol(wszPatternString, NULL, 10);
-
- if (!(wszPatternString = wcschr(wszPatternString, ',')))
- return E_INVALIDARG;
+ BYTE *mask, *expect, *actual;
+ ULONG size, offset, i;
+ BOOL ret = TRUE;
- wszPatternString++; /* skip ',' */
+ /* format: "offset, size, mask, value" */
- ulBytes = wcstol(wszPatternString, NULL, 10);
+ offset = wcstol(pattern, NULL, 10);
- pbMask = HeapAlloc(GetProcessHeap(), 0, ulBytes);
- pbValue = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ulBytes);
- pbFile = HeapAlloc(GetProcessHeap(), 0, ulBytes);
+ if (!(pattern = wcschr(pattern, ',')))
+ return FALSE;
+ pattern++;
- /* default mask is match everything */
- memset(pbMask, 0xFF, ulBytes);
+ size = wcstol(pattern, NULL, 10);
+ mask = heap_alloc(size);
+ expect = heap_alloc(size);
+ memset(mask, 0xff, size);
- if (!(wszPatternString = wcschr(wszPatternString, ',')))
- hr = E_INVALIDARG;
+ if (!(pattern = wcschr(pattern, ',')))
+ return FALSE;
+ pattern++;
+ while (!iswxdigit(*pattern) && (*pattern != ','))
+ pattern++;
- if (hr == S_OK)
+ for (i = 0; iswxdigit(*pattern) && (i/2 < size); pattern++, i++)
{
- wszPatternString++; /* skip ',' */
- while (!iswxdigit(*wszPatternString) && (*wszPatternString != ',')) wszPatternString++;
+ if (i % 2)
+ mask[i / 2] |= byte_from_hex_char(*pattern);
+ else
+ mask[i / 2] = byte_from_hex_char(*pattern) << 4;
+ }
- for (strpos = 0; iswxdigit(*wszPatternString) && (strpos/2 < ulBytes); wszPatternString++, strpos++)
- {
- if ((strpos % 2) == 1) /* odd numbered position */
- pbMask[strpos / 2] |= byte_from_hex_char(*wszPatternString);
- else
- pbMask[strpos / 2] = byte_from_hex_char(*wszPatternString) << 4;
- }
+ if (!(pattern = wcschr(pattern, ',')))
+ {
+ heap_free(mask);
+ heap_free(expect);
+ return FALSE;
+ }
+ pattern++;
+ while (!iswxdigit(*pattern) && (*pattern != ','))
+ pattern++;
- if (!(wszPatternString = wcschr(wszPatternString, ',')))
- hr = E_INVALIDARG;
+ for (i = 0; iswxdigit(*pattern) && (i/2 < size); pattern++, i++)
+ {
+ if (i % 2)
+ expect[i / 2] |= byte_from_hex_char(*pattern);
else
- wszPatternString++; /* skip ',' */
+ expect[i / 2] = byte_from_hex_char(*pattern) << 4;
}
- if (hr == S_OK)
+ actual = heap_alloc(size);
+ if (FAILED(IAsyncReader_SyncRead(reader, offset, size, actual)))
{
- for ( ; !iswxdigit(*wszPatternString) && (*wszPatternString != ','); wszPatternString++)
- ;
+ heap_free(actual);
+ heap_free(expect);
+ heap_free(mask);
+ return FALSE;
+ }
- for (strpos = 0; iswxdigit(*wszPatternString) && (strpos/2 < ulBytes); wszPatternString++, strpos++)
+ for (i = 0; i < size; ++i)
+ {
+ if ((actual[i] & mask[i]) != expect[i])
{
- if ((strpos % 2) == 1) /* odd numbered position */
- pbValue[strpos / 2] |= byte_from_hex_char(*wszPatternString);
- else
- pbValue[strpos / 2] = byte_from_hex_char(*wszPatternString) << 4;
+ ret = FALSE;
+ break;
}
}
- if (hr == S_OK)
- hr = IAsyncReader_SyncRead(pReader, ulOffset, ulBytes, pbFile);
-
- if (hr == S_OK)
- {
- ULONG i;
- for (i = 0; i < ulBytes; i++)
- if ((pbFile[i] & pbMask[i]) != pbValue[i])
- {
- hr = S_FALSE;
- break;
- }
- }
+ heap_free(actual);
+ heap_free(expect);
+ heap_free(mask);
- HeapFree(GetProcessHeap(), 0, pbMask);
- HeapFree(GetProcessHeap(), 0, pbValue);
- HeapFree(GetProcessHeap(), 0, pbFile);
+ /* If there is a following tuple, then we must match that as well. */
+ if (ret && (pattern = wcschr(pattern, ',')))
+ return process_pattern_string(pattern + 1, reader);
- /* if we encountered no errors with this string, and there is a following tuple, then we
- * have to match that as well to succeed */
- if ((hr == S_OK) && (wszPatternString = wcschr(wszPatternString, ',')))
- return process_pattern_string(wszPatternString + 1, pReader);
- else
- return hr;
+ return ret;
}
BOOL get_media_type(IAsyncReader *reader, const WCHAR *filename, GUID *majortype,
@@ -308,7 +298,7 @@ BOOL get_media_type(IAsyncReader *reader, const WCHAR *filename, GUID *majortype
if (!wcscmp(value_name, source_filter_name))
continue;
- if (process_pattern_string(pattern, reader) != S_OK)
+ if (!process_pattern_string(pattern, reader))
continue;
if (majortype)
More information about the wine-cvs
mailing list