Don't even try to allocate 2GiB on LP32.
std::vector will just throw std::length_error anyway... Bug: http://b/241114825 Test: treehugger Change-Id: I44a9be9a5357c7b3a1c1d1273ef90a023a91e81b
This commit is contained in:
parent
cede011a2c
commit
0cac2919fd
|
@ -2940,28 +2940,38 @@ TEST(STDIO_TEST, freopen_null_filename_mode) {
|
|||
fclose(fp);
|
||||
}
|
||||
|
||||
#if defined(__LP64__)
|
||||
static int64_t GetTotalRamGiB() {
|
||||
struct sysinfo si;
|
||||
sysinfo(&si);
|
||||
return (static_cast<int64_t>(si.totalram) * si.mem_unit) / 1024 / 1024 / 1024;
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST(STDIO_TEST, fread_int_overflow) {
|
||||
#if defined(__LP64__)
|
||||
if (GetTotalRamGiB() <= 4) GTEST_SKIP() << "not enough memory";
|
||||
|
||||
const size_t too_big_for_an_int = 0x80000000ULL;
|
||||
std::vector<char> buf(too_big_for_an_int);
|
||||
std::unique_ptr<FILE, decltype(&fclose)> fp{fopen("/dev/zero", "re"), fclose};
|
||||
ASSERT_EQ(too_big_for_an_int, fread(&buf[0], 1, too_big_for_an_int, fp.get()));
|
||||
#else
|
||||
GTEST_SKIP() << "32-bit can't allocate 2GiB";
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(STDIO_TEST, fwrite_int_overflow) {
|
||||
#if defined(__LP64__)
|
||||
if (GetTotalRamGiB() <= 4) GTEST_SKIP() << "not enough memory";
|
||||
|
||||
const size_t too_big_for_an_int = 0x80000000ULL;
|
||||
std::vector<char> buf(too_big_for_an_int);
|
||||
std::unique_ptr<FILE, decltype(&fclose)> fp{fopen("/dev/null", "we"), fclose};
|
||||
ASSERT_EQ(too_big_for_an_int, fwrite(&buf[0], 1, too_big_for_an_int, fp.get()));
|
||||
#else
|
||||
GTEST_SKIP() << "32-bit can't allocate 2GiB";
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(STDIO_TEST, snprintf_b) {
|
||||
|
|
Loading…
Reference in New Issue