From c6a94a7f3556c8dc998630aa65b4e812c7898ad1 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Sat, 17 Oct 2020 19:36:11 -0500 Subject: Update verutil precedence rules to check for invalid after release labels. --- src/dutil/verutil.cpp | 57 +++++++++++++++++---------------- src/test/DUtilUnitTest/VerUtilTests.cpp | 44 ++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/dutil/verutil.cpp b/src/dutil/verutil.cpp index f362f413..835dde81 100644 --- a/src/dutil/verutil.cpp +++ b/src/dutil/verutil.cpp @@ -85,22 +85,6 @@ DAPI_(HRESULT) VerCompareParsedVersions( ExitFunction(); } - if (pVersion1->fInvalid) - { - if (!pVersion2->fInvalid) - { - ExitFunction1(nResult = -1); - } - else - { - fCompareMetadata = TRUE; - } - } - else if (pVersion2->fInvalid) - { - ExitFunction1(nResult = 1); - } - if (pVersion1->cReleaseLabels) { if (pVersion2->cReleaseLabels) @@ -132,6 +116,22 @@ DAPI_(HRESULT) VerCompareParsedVersions( } } + if (pVersion1->fInvalid) + { + if (!pVersion2->fInvalid) + { + ExitFunction1(nResult = -1); + } + else + { + fCompareMetadata = TRUE; + } + } + else if (pVersion2->fInvalid) + { + ExitFunction1(nResult = 1); + } + if (fCompareMetadata) { hr = CompareVersionSubstring(pVersion1->sczVersion + pVersion1->cchMetadataOffset, -1, pVersion2->sczVersion + pVersion2->cchMetadataOffset, -1, &nResult); @@ -191,20 +191,23 @@ DAPI_(HRESULT) VerCopyVersion( pCopy->dwPatch = pSource->dwPatch; pCopy->dwRevision = pSource->dwRevision; - hr = MemEnsureArraySize(reinterpret_cast(&pCopy->rgReleaseLabels), 0, sizeof(VERUTIL_VERSION_RELEASE_LABEL), pSource->cReleaseLabels); - VerExitOnFailure(hr, "Failed to allocate memory for Verutil version release labels copies."); + if (pSource->cReleaseLabels) + { + hr = MemEnsureArraySize(reinterpret_cast(&pCopy->rgReleaseLabels), 0, sizeof(VERUTIL_VERSION_RELEASE_LABEL), pSource->cReleaseLabels); + VerExitOnFailure(hr, "Failed to allocate memory for Verutil version release labels copies."); - pCopy->cReleaseLabels = pSource->cReleaseLabels; + pCopy->cReleaseLabels = pSource->cReleaseLabels; - for (DWORD i = 0; i < pCopy->cReleaseLabels; ++i) - { - VERUTIL_VERSION_RELEASE_LABEL* pSourceLabel = pSource->rgReleaseLabels + i; - VERUTIL_VERSION_RELEASE_LABEL* pCopyLabel = pCopy->rgReleaseLabels + i; + for (DWORD i = 0; i < pCopy->cReleaseLabels; ++i) + { + VERUTIL_VERSION_RELEASE_LABEL* pSourceLabel = pSource->rgReleaseLabels + i; + VERUTIL_VERSION_RELEASE_LABEL* pCopyLabel = pCopy->rgReleaseLabels + i; - pCopyLabel->cchLabelOffset = pSourceLabel->cchLabelOffset; - pCopyLabel->cchLabel = pSourceLabel->cchLabel; - pCopyLabel->fNumeric = pSourceLabel->fNumeric; - pCopyLabel->dwValue = pSourceLabel->dwValue; + pCopyLabel->cchLabelOffset = pSourceLabel->cchLabelOffset; + pCopyLabel->cchLabel = pSourceLabel->cchLabel; + pCopyLabel->fNumeric = pSourceLabel->fNumeric; + pCopyLabel->dwValue = pSourceLabel->dwValue; + } } pCopy->cchMetadataOffset = pSource->cchMetadataOffset; diff --git a/src/test/DUtilUnitTest/VerUtilTests.cpp b/src/test/DUtilUnitTest/VerUtilTests.cpp index 58b561e9..8f24ad1a 100644 --- a/src/test/DUtilUnitTest/VerUtilTests.cpp +++ b/src/test/DUtilUnitTest/VerUtilTests.cpp @@ -237,7 +237,7 @@ namespace DutilTests TestVerutilCompareParsedVersions(pVersion1, pVersion2, 1); TestVerutilCompareParsedVersions(pVersion3, pVersion4, 1); - TestVerutilCompareParsedVersions(pVersion5, pVersion6, 1); + TestVerutilCompareParsedVersions(pVersion5, pVersion6, -1); } finally { @@ -661,6 +661,48 @@ namespace DutilTests [Fact] void VerCopyVersionCopiesVersion() + { + HRESULT hr = S_OK; + LPCWSTR wzVersion = L"1.2.3.4+abc123"; + VERUTIL_VERSION* pSource = NULL; + VERUTIL_VERSION* pCopy = NULL; + int nResult = 0; + + try + { + hr = VerParseVersion(wzVersion, 0, FALSE, &pSource); + NativeAssert::Succeeded(hr, "VerParseVersion failed"); + + NativeAssert::StringEqual(wzVersion, pSource->sczVersion); + Assert::Equal(1, pSource->dwMajor); + Assert::Equal(2, pSource->dwMinor); + Assert::Equal(3, pSource->dwPatch); + Assert::Equal(4, pSource->dwRevision); + Assert::Equal(0, pSource->cReleaseLabels); + + Assert::Equal(8, pSource->cchMetadataOffset); + Assert::Equal(FALSE, pSource->fInvalid); + + hr = VerCopyVersion(pSource, &pCopy); + NativeAssert::Succeeded(hr, "VerCopyVersion failed"); + + Assert::False(pSource == pCopy); + Assert::False(pSource->sczVersion == pCopy->sczVersion); + + hr = VerCompareParsedVersions(pSource, pCopy, &nResult); + NativeAssert::Succeeded(hr, "VerCompareParsedVersions failed"); + + Assert::Equal(nResult, 0); + } + finally + { + ReleaseVerutilVersion(pCopy); + ReleaseVerutilVersion(pSource); + } + } + + [Fact] + void VerCopyVersionCopiesPrereleaseVersion() { HRESULT hr = S_OK; LPCWSTR wzVersion = L"1.2.3.4-a.b.c.d.5.+abc123"; -- cgit v1.2.3-55-g6feb