Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5ae64c9

Browse files
Olli EtuahoCommit Bot
authored andcommitted
Fix writing hex values in ImmutableStringBuilder
The old code was accidentally using letters offset by 10 when writing out hex values >= 10. Now the letters a to f are used as they should. This is one issue that changed shader output when ImmutableString was introduced, so it is a potential cause for a regression detailed in bug 824062, though this has not been verified. BUG=chromium:824062 TEST=angle_unittests Change-Id: Idb871dffba32a3ab20df0fe17b4b1a98ec00b7fa Reviewed-on: https://chromium-review.googlesource.com/999480 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
1 parent e547aac commit 5ae64c9

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

src/compiler/translator/ImmutableStringBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ImmutableStringBuilder
4747
while (index >= 0)
4848
{
4949
char digit = static_cast<char>((number >> (index * 4)) & 0xfu);
50-
char digitChar = digit < 10 ? digit + '0' : digit + 'a';
50+
char digitChar = (digit < 10) ? (digit + '0') : (digit + ('a' - 10));
5151
mData[mPos++] = digitChar;
5252
--index;
5353
}

src/tests/angle_unittests.gypi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
'<(angle_path)/src/tests/compiler_tests/GLSLCompatibilityOutput_test.cpp',
7373
'<(angle_path)/src/tests/compiler_tests/GlFragDataNotModified_test.cpp',
7474
'<(angle_path)/src/tests/compiler_tests/GeometryShader_test.cpp',
75+
'<(angle_path)/src/tests/compiler_tests/ImmutableString_test.cpp',
7576
'<(angle_path)/src/tests/compiler_tests/ImmutableString_test_autogen.cpp',
7677
'<(angle_path)/src/tests/compiler_tests/InitOutputVariables_test.cpp',
7778
'<(angle_path)/src/tests/compiler_tests/IntermNode_test.cpp',
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
//
5+
// ImmutableString_test.cpp:
6+
// Tests for ImmutableString and ImmutableStringBuilder.
7+
8+
#include "compiler/translator/ImmutableString.h"
9+
#include "compiler/translator/ImmutableStringBuilder.h"
10+
#include "compiler/translator/PoolAlloc.h"
11+
#include "gtest/gtest.h"
12+
13+
using namespace sh;
14+
15+
class ImmutableStringBuilderTest : public testing::Test
16+
{
17+
public:
18+
ImmutableStringBuilderTest() {}
19+
20+
protected:
21+
void SetUp() override
22+
{
23+
allocator.push();
24+
SetGlobalPoolAllocator(&allocator);
25+
}
26+
27+
void TearDown() override
28+
{
29+
SetGlobalPoolAllocator(nullptr);
30+
allocator.pop();
31+
}
32+
33+
TPoolAllocator allocator;
34+
};
35+
36+
// Test writing a 32-bit signed int as hexadecimal using ImmutableStringBuilder.
37+
TEST_F(ImmutableStringBuilderTest, AppendHexInt32)
38+
{
39+
int32_t i = -1;
40+
ImmutableStringBuilder strBuilder(2 * sizeof(int32_t));
41+
strBuilder.appendHex(i);
42+
ImmutableString str = strBuilder;
43+
EXPECT_EQ(std::string("ffffffff"), str.data());
44+
}
45+
46+
// Test writing a 32-bit unsigned int as hexadecimal using ImmutableStringBuilder.
47+
TEST_F(ImmutableStringBuilderTest, AppendHexUint32)
48+
{
49+
uint32_t i = 0x1234beefu;
50+
ImmutableStringBuilder strBuilder(2 * sizeof(uint32_t));
51+
strBuilder.appendHex(i);
52+
ImmutableString str = strBuilder;
53+
EXPECT_EQ(std::string("1234beef"), str.data());
54+
}
55+
56+
// Test writing a 64-bit signed int as hexadecimal using ImmutableStringBuilder.
57+
TEST_F(ImmutableStringBuilderTest, AppendHexInt64)
58+
{
59+
int64_t i = -1;
60+
ImmutableStringBuilder strBuilder(2 * sizeof(int64_t));
61+
strBuilder.appendHex(i);
62+
ImmutableString str = strBuilder;
63+
EXPECT_EQ(std::string("ffffffffffffffff"), str.data());
64+
}
65+
66+
// Test writing a 64-bit unsigned int as hexadecimal using ImmutableStringBuilder.
67+
TEST_F(ImmutableStringBuilderTest, AppendHexUint64)
68+
{
69+
uint64_t i = 0xfeedcafe9876beefull;
70+
ImmutableStringBuilder strBuilder(2 * sizeof(uint64_t));
71+
strBuilder.appendHex(i);
72+
ImmutableString str = strBuilder;
73+
EXPECT_EQ(std::string("feedcafe9876beef"), str.data());
74+
}

0 commit comments

Comments
 (0)