@joebigelow / wix / commits / c6a94a7f

Update verutil precedence rules to check for invalid after release labels.

Sean Hall committed Oct 17, 2020 at 19:36 UTC c6a94a7f3556c8dc998630aa65b4e812c7898ad1
2 files changed +73 -28
src/dutil/verutil.cpp
+30 -27
@@ -85,22 +85,6 @@ DAPI_(HRESULT) VerCompareParsedVersions(
85 ExitFunction();
86 }
87
88 - if (pVersion1->fInvalid)
89 - {
90 - if (!pVersion2->fInvalid)
91 - {
92 - ExitFunction1(nResult = -1);
93 - }
94 - else
95 - {
96 - fCompareMetadata = TRUE;
97 - }
98 - }
99 - else if (pVersion2->fInvalid)
100 - {
101 - ExitFunction1(nResult = 1);
102 - }
103 -
88 if (pVersion1->cReleaseLabels)
89 {
90 if (pVersion2->cReleaseLabels)
@@ -132,6 +116,22 @@ DAPI_(HRESULT) VerCompareParsedVersions(
116 }
117 }
118
119 + if (pVersion1->fInvalid)
120 + {
121 + if (!pVersion2->fInvalid)
122 + {
123 + ExitFunction1(nResult = -1);
124 + }
125 + else
126 + {
127 + fCompareMetadata = TRUE;
128 + }
129 + }
130 + else if (pVersion2->fInvalid)
131 + {
132 + ExitFunction1(nResult = 1);
133 + }
134 +
135 if (fCompareMetadata)
136 {
137 hr = CompareVersionSubstring(pVersion1->sczVersion + pVersion1->cchMetadataOffset, -1, pVersion2->sczVersion + pVersion2->cchMetadataOffset, -1, &nResult);
@@ -191,20 +191,23 @@ DAPI_(HRESULT) VerCopyVersion(
191 pCopy->dwPatch = pSource->dwPatch;
192 pCopy->dwRevision = pSource->dwRevision;
193
194 - hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(&pCopy->rgReleaseLabels), 0, sizeof(VERUTIL_VERSION_RELEASE_LABEL), pSource->cReleaseLabels);
195 - VerExitOnFailure(hr, "Failed to allocate memory for Verutil version release labels copies.");
194 + if (pSource->cReleaseLabels)
195 + {
196 + hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(&pCopy->rgReleaseLabels), 0, sizeof(VERUTIL_VERSION_RELEASE_LABEL), pSource->cReleaseLabels);
197 + VerExitOnFailure(hr, "Failed to allocate memory for Verutil version release labels copies.");
198
197 - pCopy->cReleaseLabels = pSource->cReleaseLabels;
199 + pCopy->cReleaseLabels = pSource->cReleaseLabels;
200
199 - for (DWORD i = 0; i < pCopy->cReleaseLabels; ++i)
200 - {
201 - VERUTIL_VERSION_RELEASE_LABEL* pSourceLabel = pSource->rgReleaseLabels + i;
202 - VERUTIL_VERSION_RELEASE_LABEL* pCopyLabel = pCopy->rgReleaseLabels + i;
201 + for (DWORD i = 0; i < pCopy->cReleaseLabels; ++i)
202 + {
203 + VERUTIL_VERSION_RELEASE_LABEL* pSourceLabel = pSource->rgReleaseLabels + i;
204 + VERUTIL_VERSION_RELEASE_LABEL* pCopyLabel = pCopy->rgReleaseLabels + i;
205
204 - pCopyLabel->cchLabelOffset = pSourceLabel->cchLabelOffset;
205 - pCopyLabel->cchLabel = pSourceLabel->cchLabel;
206 - pCopyLabel->fNumeric = pSourceLabel->fNumeric;
207 - pCopyLabel->dwValue = pSourceLabel->dwValue;
206 + pCopyLabel->cchLabelOffset = pSourceLabel->cchLabelOffset;
207 + pCopyLabel->cchLabel = pSourceLabel->cchLabel;
208 + pCopyLabel->fNumeric = pSourceLabel->fNumeric;
209 + pCopyLabel->dwValue = pSourceLabel->dwValue;
210 + }
211 }
212
213 pCopy->cchMetadataOffset = pSource->cchMetadataOffset;
src/test/DUtilUnitTest/VerUtilTests.cpp
+43 -1
@@ -237,7 +237,7 @@ namespace DutilTests
237
238 TestVerutilCompareParsedVersions(pVersion1, pVersion2, 1);
239 TestVerutilCompareParsedVersions(pVersion3, pVersion4, 1);
240 - TestVerutilCompareParsedVersions(pVersion5, pVersion6, 1);
240 + TestVerutilCompareParsedVersions(pVersion5, pVersion6, -1);
241 }
242 finally
243 {
@@ -661,6 +661,48 @@ namespace DutilTests
661
662 [Fact]
663 void VerCopyVersionCopiesVersion()
664 + {
665 + HRESULT hr = S_OK;
666 + LPCWSTR wzVersion = L"1.2.3.4+abc123";
667 + VERUTIL_VERSION* pSource = NULL;
668 + VERUTIL_VERSION* pCopy = NULL;
669 + int nResult = 0;
670 +
671 + try
672 + {
673 + hr = VerParseVersion(wzVersion, 0, FALSE, &pSource);
674 + NativeAssert::Succeeded(hr, "VerParseVersion failed");
675 +
676 + NativeAssert::StringEqual(wzVersion, pSource->sczVersion);
677 + Assert::Equal<DWORD>(1, pSource->dwMajor);
678 + Assert::Equal<DWORD>(2, pSource->dwMinor);
679 + Assert::Equal<DWORD>(3, pSource->dwPatch);
680 + Assert::Equal<DWORD>(4, pSource->dwRevision);
681 + Assert::Equal<DWORD>(0, pSource->cReleaseLabels);
682 +
683 + Assert::Equal<DWORD>(8, pSource->cchMetadataOffset);
684 + Assert::Equal<BOOL>(FALSE, pSource->fInvalid);
685 +
686 + hr = VerCopyVersion(pSource, &pCopy);
687 + NativeAssert::Succeeded(hr, "VerCopyVersion failed");
688 +
689 + Assert::False(pSource == pCopy);
690 + Assert::False(pSource->sczVersion == pCopy->sczVersion);
691 +
692 + hr = VerCompareParsedVersions(pSource, pCopy, &nResult);
693 + NativeAssert::Succeeded(hr, "VerCompareParsedVersions failed");
694 +
695 + Assert::Equal<int>(nResult, 0);
696 + }
697 + finally
698 + {
699 + ReleaseVerutilVersion(pCopy);
700 + ReleaseVerutilVersion(pSource);
701 + }
702 + }
703 +
704 + [Fact]
705 + void VerCopyVersionCopiesPrereleaseVersion()
706 {
707 HRESULT hr = S_OK;
708 LPCWSTR wzVersion = L"1.2.3.4-a.b.c.d.5.+abc123";