45 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: 32-bit-pointer10// REQUIRES: large_tests11 12// This bug was fixed in the dylib by 53aed4759b33e33614e0f4e321bc1ef764b6d5b6.13// XFAIL: using-built-library-before-llvm-1714 15// Android devices frequently don't have enough memory to run this test. Rather16// than throw std::bad_alloc, exhausting memory triggers the OOM Killer.17// UNSUPPORTED: LIBCXX-ANDROID-FIXME18 19// Test that tellp() does not break the stringstream after INT_MAX, due to use20// of pbump() that accept int.21 22#include <cassert>23#include <climits>24#include <sstream>25#include <string>26 27int main(int, char**) {28 std::stringstream ss;29 std::string payload(INT_MAX - 1, '\0');30 31 ss.write(payload.data(), payload.size());32 assert(ss.tellp() == INT_MAX - 1);33 34 ss.write("a", 1);35 assert(ss.tellp() == INT_MAX);36 37 ss.write("b", 1);38 assert(ss.tellp() == INT_MAX + 1ULL);39 // it fails only after previous tellp() corrupts the internal field with int40 // overflow41 assert(ss.tellp() == INT_MAX + 1ULL);42 43 return 0;44}45