forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libcxx] Fix crash in std::stringstream with payload >= INT_MAX
stringstream does works for payload > INT_MAX, however stringstream::gcount() can break the internal field (__nout_) and this breaks the stringstream itself, and so the program will crash. Fix this, by using __pbump(streamsize) over pbump(int) Note, libstdc++ does not have this bug. Signed-off-by: Azat Khuzhin <[email protected]> Differential Revision: https://reviews.llvm.org/D146294
- Loading branch information
Showing
2 changed files
with
38 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
libcxx/test/std/input.output/string.streams/stringstream.members/gcount.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// <sstream> | ||
|
||
// Test that tellp() does not break the stringstream after INT_MAX, due to use | ||
// of pbump() that accept int. | ||
|
||
#include <string> | ||
#include <sstream> | ||
#include <cassert> | ||
|
||
int main(int, char**) { | ||
#if __SIZE_WIDTH__ == 64 | ||
std::stringstream ss; | ||
std::string payload(1 << 20, 'A'); | ||
|
||
for (size_t i = 0; i < (2ULL << 30) - payload.size(); i += payload.size()) { | ||
assert(ss.tellp() != -1); | ||
ss.write(payload.data(), payload.size()); | ||
} | ||
|
||
assert(ss.tellp() != -1); | ||
ss.write(payload.data(), payload.size()); | ||
|
||
assert(ss.tellp() != -1); | ||
ss.write(payload.data(), payload.size()); | ||
#endif | ||
|
||
return 0; | ||
} |