Skip to content

Commit 657d13c

Browse files
committed
Merged PR 5769: Replace incorrect sizeof() with strlen() in compiler version test
Replace incorrect sizeof() with strlen() in compiler version test This would produce a failure only on x86 because it sizeof() gave the size of a pointer, which just so happens to be the hard coded size of the hash on x64. On x86, it would advance only 4 bytes, and fail the comparison. This also checks to see if the VersionStringListSizeInBytes is > 2 more than the hash size, because both null-terminators are always added, so it will always be at least 2 more, even with no CustomVersionString.
1 parent 7f6d946 commit 657d13c

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

tools/clang/unittests/HLSL/DxilContainerTest.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,10 +2110,12 @@ TEST_F(DxilContainerTest, DxilContainerCompilerVersionTest) {
21102110

21112111
if (pDCV->VersionStringListSizeInBytes != 0) {
21122112
LPCSTR pCommitHashStr = (LPCSTR)pDCV + sizeof(hlsl::DxilCompilerVersion);
2113+
uint32_t uCommitHashLen = (uint32_t)strlen(pCommitHashStr);
21132114

21142115
VERIFY_ARE_EQUAL_STR(pCommitHashStr, pCommitHashRef);
2115-
if (pDCV->VersionStringListSizeInBytes > sizeof(pCommitHashStr) + 1) {
2116-
LPCSTR pCustomVersionString = pCommitHashStr + sizeof(pCommitHashStr) + 1;
2116+
// + 2 for the two null terminators that are included in this size:
2117+
if (pDCV->VersionStringListSizeInBytes > uCommitHashLen + 2) {
2118+
LPCSTR pCustomVersionString = pCommitHashStr + uCommitHashLen + 1;
21172119
VERIFY_ARE_EQUAL_STR(pCustomVersionString, pCustomVersionStrRef)
21182120
}
21192121
}

0 commit comments

Comments
 (0)