Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions stl/inc/__msvc_filebuf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,7 @@ class basic_filebuf : public basic_streambuf<_Elem, _Traits> { // stream buffer
_Off -= static_cast<off_type>(sizeof(_Elem)); // back up over _Elem bytes
}

if (!_Myfile || !_Endwrite()
|| ((_Off != 0 || _Way != ios_base::cur) && _CSTD _fseeki64(_Myfile, _Off, _Way) != 0)
if (!_Myfile || !_Endwrite() || _CSTD _fseeki64(_Myfile, _Off, _Way) != 0
|| _CSTD fgetpos(_Myfile, &_Fileposition) != 0) {
return pos_type{off_type{-1}}; // report failure
}
Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ tests\GH_003105_piecewise_densities
tests\GH_003119_error_category_ctor
tests\GH_003246_cmath_narrowing
tests\GH_003570_allocate_at_least
tests\GH_003572_fstream_seekp_0_cur
tests\GH_003617_vectorized_meow_element
tests\GH_003676_format_large_hh_mm_ss_values
tests\GH_003735_char_traits_signatures
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/GH_003572_fstream_seekp_0_cur/env.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\usual_matrix.lst
47 changes: 47 additions & 0 deletions tests/std/tests/GH_003572_fstream_seekp_0_cur/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <cassert>
#include <cstring>
#include <fstream>
#include <ios>

int main() {
using namespace std;

fstream f("test.txt", ios::in | ios::out | ios::trunc);
Comment thread
StephanTLavavej marked this conversation as resolved.

f << "123";

auto check = [&f](const char(&content)[4]) {
char buffer[4]{};
f.seekg(0);
f.read(buffer, 3);
assert(f);
assert(memcmp(buffer, content, 4) == 0);
};

f.seekg(0);
(void) f.get();
f.seekp(f.tellp());
f << "*";
check("1*3");

f.seekg(0);
(void) f.get();
f.seekp(0, ios::cur);
f << "!";
check("1!3");

f.seekg(0);
(void) f.get();
f.seekp(1, ios::cur);
f << "!";
check("1!!");

f.seekg(0);
(void) f.get();
f.seekp(-1, ios::cur);
f << "!";
check("!!!");
}