diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2022-05-16 16:03:25 -0500 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2022-05-17 22:54:13 -0500 |
commit | 0ea53e27361cbfe664df98d717e55005f329aff1 (patch) | |
tree | d75e02fadee9669593ca3ccf28401b67064244af /src/libs/dutil/WixToolset.DUtil | |
parent | d5985a1688bc878e42ffd3ce3939fa52303cab16 (diff) | |
download | wix-0ea53e27361cbfe664df98d717e55005f329aff1.tar.gz wix-0ea53e27361cbfe664df98d717e55005f329aff1.tar.bz2 wix-0ea53e27361cbfe664df98d717e55005f329aff1.zip |
Store the prefix character in VERUTIL_VERSION.
Fix edge case where version string is all v's.
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil')
-rw-r--r-- | src/libs/dutil/WixToolset.DUtil/inc/verutil.h | 1 | ||||
-rw-r--r-- | src/libs/dutil/WixToolset.DUtil/verutil.cpp | 37 |
2 files changed, 26 insertions, 12 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/inc/verutil.h b/src/libs/dutil/WixToolset.DUtil/inc/verutil.h index 5247bb61..4fdaa522 100644 --- a/src/libs/dutil/WixToolset.DUtil/inc/verutil.h +++ b/src/libs/dutil/WixToolset.DUtil/inc/verutil.h | |||
@@ -19,6 +19,7 @@ typedef struct _VERUTIL_VERSION_RELEASE_LABEL | |||
19 | typedef struct _VERUTIL_VERSION | 19 | typedef struct _VERUTIL_VERSION |
20 | { | 20 | { |
21 | LPWSTR sczVersion; | 21 | LPWSTR sczVersion; |
22 | WCHAR chPrefix; | ||
22 | DWORD dwMajor; | 23 | DWORD dwMajor; |
23 | DWORD dwMinor; | 24 | DWORD dwMinor; |
24 | DWORD dwPatch; | 25 | DWORD dwPatch; |
diff --git a/src/libs/dutil/WixToolset.DUtil/verutil.cpp b/src/libs/dutil/WixToolset.DUtil/verutil.cpp index 8881d7bc..30b979b1 100644 --- a/src/libs/dutil/WixToolset.DUtil/verutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/verutil.cpp | |||
@@ -194,6 +194,7 @@ DAPI_(HRESULT) VerCopyVersion( | |||
194 | hr = StrAllocString(&pCopy->sczVersion, pSource->sczVersion, 0); | 194 | hr = StrAllocString(&pCopy->sczVersion, pSource->sczVersion, 0); |
195 | VerExitOnFailure(hr, "Failed to copy Verutil version string '%ls'.", pSource->sczVersion); | 195 | VerExitOnFailure(hr, "Failed to copy Verutil version string '%ls'.", pSource->sczVersion); |
196 | 196 | ||
197 | pCopy->chPrefix = pSource->chPrefix; | ||
197 | pCopy->dwMajor = pSource->dwMajor; | 198 | pCopy->dwMajor = pSource->dwMajor; |
198 | pCopy->dwMinor = pSource->dwMinor; | 199 | pCopy->dwMinor = pSource->dwMinor; |
199 | pCopy->dwPatch = pSource->dwPatch; | 200 | pCopy->dwPatch = pSource->dwPatch; |
@@ -251,6 +252,7 @@ DAPI_(HRESULT) VerParseVersion( | |||
251 | { | 252 | { |
252 | HRESULT hr = S_OK; | 253 | HRESULT hr = S_OK; |
253 | VERUTIL_VERSION* pVersion = NULL; | 254 | VERUTIL_VERSION* pVersion = NULL; |
255 | LPCWSTR wzString = NULL; | ||
254 | LPCWSTR wzEnd = NULL; | 256 | LPCWSTR wzEnd = NULL; |
255 | LPCWSTR wzPartBegin = NULL; | 257 | LPCWSTR wzPartBegin = NULL; |
256 | LPCWSTR wzPartEnd = NULL; | 258 | LPCWSTR wzPartEnd = NULL; |
@@ -277,22 +279,22 @@ DAPI_(HRESULT) VerParseVersion( | |||
277 | VerExitOnRootFailure(hr = E_INVALIDARG, "Version string is too long: %Iu", cchVersion); | 279 | VerExitOnRootFailure(hr = E_INVALIDARG, "Version string is too long: %Iu", cchVersion); |
278 | } | 280 | } |
279 | 281 | ||
280 | if (L'v' == *wzVersion || L'V' == *wzVersion) | ||
281 | { | ||
282 | ++wzVersion; | ||
283 | --cchVersion; | ||
284 | } | ||
285 | |||
286 | pVersion = reinterpret_cast<VERUTIL_VERSION*>(MemAlloc(sizeof(VERUTIL_VERSION), TRUE)); | 282 | pVersion = reinterpret_cast<VERUTIL_VERSION*>(MemAlloc(sizeof(VERUTIL_VERSION), TRUE)); |
287 | VerExitOnNull(pVersion, hr, E_OUTOFMEMORY, "Failed to allocate memory for Verutil version '%ls'.", wzVersion); | 283 | VerExitOnNull(pVersion, hr, E_OUTOFMEMORY, "Failed to allocate memory for Verutil version '%ls'.", wzVersion); |
288 | 284 | ||
289 | hr = StrAllocString(&pVersion->sczVersion, wzVersion, cchVersion); | 285 | wzString = wzVersion; |
290 | VerExitOnFailure(hr, "Failed to copy Verutil version string '%ls'.", wzVersion); | 286 | |
287 | if (L'v' == *wzString || L'V' == *wzString) | ||
288 | { | ||
289 | pVersion->chPrefix = *wzString; | ||
290 | ++wzString; | ||
291 | --cchVersion; | ||
292 | } | ||
291 | 293 | ||
292 | wzVersion = wzPartBegin = wzPartEnd = pVersion->sczVersion; | 294 | wzPartBegin = wzPartEnd = wzString; |
293 | 295 | ||
294 | // Save end pointer. | 296 | // Save end pointer. |
295 | wzEnd = wzVersion + cchVersion; | 297 | wzEnd = wzString + cchVersion; |
296 | 298 | ||
297 | // Parse version number | 299 | // Parse version number |
298 | while (wzPartBegin < wzEnd) | 300 | while (wzPartBegin < wzEnd) |
@@ -473,7 +475,7 @@ DAPI_(HRESULT) VerParseVersion( | |||
473 | pReleaseLabel->dwValue = uLabel; | 475 | pReleaseLabel->dwValue = uLabel; |
474 | } | 476 | } |
475 | 477 | ||
476 | pReleaseLabel->cchLabelOffset = wzPartBegin - pVersion->sczVersion; | 478 | pReleaseLabel->cchLabelOffset = wzPartBegin - wzString; |
477 | pReleaseLabel->cchLabel = cchLabel; | 479 | pReleaseLabel->cchLabel = cchLabel; |
478 | 480 | ||
479 | if (fTrailingDot) | 481 | if (fTrailingDot) |
@@ -507,9 +509,20 @@ DAPI_(HRESULT) VerParseVersion( | |||
507 | ExitFunction1(hr = E_INVALIDARG); | 509 | ExitFunction1(hr = E_INVALIDARG); |
508 | } | 510 | } |
509 | 511 | ||
510 | pVersion->cchMetadataOffset = min(wzPartBegin, wzEnd) - pVersion->sczVersion; | 512 | pVersion->cchMetadataOffset = min(wzPartBegin, wzEnd) - wzString; |
511 | pVersion->fInvalid = fInvalid; | 513 | pVersion->fInvalid = fInvalid; |
512 | 514 | ||
515 | // If the whole string was invalid, then don't clip off the prefix. | ||
516 | if (!pVersion->cchMetadataOffset && pVersion->chPrefix) | ||
517 | { | ||
518 | pVersion->chPrefix = '\0'; | ||
519 | wzString = wzVersion; | ||
520 | ++cchVersion; | ||
521 | } | ||
522 | |||
523 | hr = StrAllocString(&pVersion->sczVersion, wzString, cchVersion); | ||
524 | VerExitOnFailure(hr, "Failed to copy Verutil version string '%ls'.", wzVersion); | ||
525 | |||
513 | *ppVersion = pVersion; | 526 | *ppVersion = pVersion; |
514 | pVersion = NULL; | 527 | pVersion = NULL; |
515 | hr = S_OK; | 528 | hr = S_OK; |