Skip to content

Commit

Permalink
Merged PR 5769: Replace incorrect sizeof() with strlen() in compiler …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
tex3d committed Jun 21, 2023
1 parent 7f6d946 commit 657d13c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tools/clang/unittests/HLSL/DxilContainerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2110,10 +2110,12 @@ TEST_F(DxilContainerTest, DxilContainerCompilerVersionTest) {

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

VERIFY_ARE_EQUAL_STR(pCommitHashStr, pCommitHashRef);
if (pDCV->VersionStringListSizeInBytes > sizeof(pCommitHashStr) + 1) {
LPCSTR pCustomVersionString = pCommitHashStr + sizeof(pCommitHashStr) + 1;
// + 2 for the two null terminators that are included in this size:
if (pDCV->VersionStringListSizeInBytes > uCommitHashLen + 2) {
LPCSTR pCustomVersionString = pCommitHashStr + uCommitHashLen + 1;
VERIFY_ARE_EQUAL_STR(pCustomVersionString, pCustomVersionStrRef)
}
}
Expand Down

0 comments on commit 657d13c

Please sign in to comment.