[llvm-bugs] [Bug 51867] New: std::basic_ostream::seekp() > 2GiB
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Sep 15 05:27:12 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=51867
Bug ID: 51867
Summary: std::basic_ostream::seekp() > 2GiB
Product: libc++
Version: 12.0
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: All Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: davidwe at posteo.de
CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com
When I use the CLANG64 environment, the "seekp()" function does not work
correctly.
Everything > 2147483648 bytes ( 2 GiB ) ends in an "ios_base::clear:
unspecified iostream_category error" exception.
When I compile the example with "-D_FILE_OFFSET_BITS=64", the seekp() function
works as expected.
As an example:
#include <filesystem>
#include <fstream>
#include <iostream>
#include <stdio.h>
#define MAX_FILE_SIZE_3GiB 3221225472
#define MAX_FILE_SIZE_2GiB 2147483648
int main(int argc, char** argv)
{
try {
std::filesystem::path sourceFile =
std::filesystem::temp_directory_path() / "example_3GiB.bin";
std::ofstream ofs(sourceFile);
ofs << "this is some text in the new file\n";
ofs.close();
std::filesystem::resize_file(sourceFile, MAX_FILE_SIZE_3GiB);
std::fstream file(sourceFile);
file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
std::cout << "File size: " << std::filesystem::file_size(sourceFile)
<< '\n';
// One byte less works.
file.seekp(MAX_FILE_SIZE_2GiB - 1, std::ios_base::beg);
std::cout << "File tellp(): " << file.tellp() << '\n';
// Everything larger than 2 GiB ends in an exception
file.seekp(MAX_FILE_SIZE_2GiB + 1, std::ios_base::beg);
std::cout << "File tellp(): " << file.tellp() << '\n';
file.close();
std::filesystem::remove(sourceFile);
return 0;
} catch(std::fstream::failure const& ex) {
std::cout << ex.what() << '\n';
return 0;
} catch(std::filesystem::filesystem_error const& ex) {
std::cout << ex.what() << '\n';
return 0;
}
}
Output:
File size: 3221225472
File tellp(): 2147483647
ios_base::clear: unspecified iostream_category error
clang -v:
clang version 12.0.1
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: C:/msys64/clang64/bin
A discussion is already going on in github. (
https://github.com/msys2/MINGW-packages/issues/9585 )
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210915/eaddba07/attachment.html>
More information about the llvm-bugs
mailing list