Skip to content

Commit 69e6a84

Browse files
authored
Remove arbitrary run line length limit (microsoft#4685)
A very strange sequence of copying the run line to a stack char array of size 300, where it would not even null-terminate the line if it hit the limit, seems totally unnecessary, since it's dealing with std::strings in the first place. This would truncate and pick up garbage from the stack in the stored run line when length >= 300 characters - causing the test to fail, of course. Perhaps some of this is an artifact of some older version of the code. In any case, this change removes the extra copying step and simply uses the entire std::string result from std::getline() instead.
1 parent ecf4e0a commit 69e6a84

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

include/dxc/Test/HlslTestUtils.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -216,22 +216,15 @@ inline std::vector<std::string> GetRunLines(const LPCWSTR name) {
216216

217217
std::vector<std::string> runlines;
218218
std::string line;
219-
constexpr size_t runlinesize = 300;
220219
while (std::getline(infile, line)) {
221220
if (!HasRunLine(line))
222221
continue;
223-
char runline[runlinesize];
224-
memset(runline, 0, runlinesize);
225-
memcpy(runline, line.c_str(), min(runlinesize, line.size()));
226-
runlines.emplace_back(runline);
222+
runlines.emplace_back(line);
227223
}
228224
return runlines;
229225
}
230226

231227
inline std::string GetFirstLine(LPCWSTR name) {
232-
char firstLine[300];
233-
memset(firstLine, 0, sizeof(firstLine));
234-
235228
const std::wstring path = PathLooksAbsolute(name)
236229
? std::wstring(name)
237230
: hlsl_test::GetPathToHlslDataFile(name);
@@ -247,8 +240,9 @@ inline std::string GetFirstLine(LPCWSTR name) {
247240
VERIFY_FAIL();
248241
}
249242

250-
infile.getline(firstLine, _countof(firstLine));
251-
return firstLine;
243+
std::string line;
244+
std::getline(infile, line);
245+
return line;
252246
}
253247

254248
inline HANDLE CreateFileForReading(LPCWSTR path) {

0 commit comments

Comments
 (0)