llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Calling sync() when rdbuf() is a null pointer should return -1.

Open edfvogel opened this issue 5 years ago • 0 comments

Bugzilla Link 52155
Version 11.0
OS All
CC @mclow

Extended Description

The Standard doc for the sync() function states: if rdbuf() is a null pointer, returns -1.

It appears libc++ is missing this check.

Here's a cut/paste from a cygwin session:

$ cat t1.cpp #include extern "C" int printf(const char *a,...); using namespace std; int main() { istream x(0); int s = x.sync(); printf("value is %d\n",s); }

VogelEd@XLB3502Q4E ~/tests $ clang++ t1.cpp -o a.out

VogelEd@XLB3502Q4E ~/tests $ ./a.out value is -1

VogelEd@XLB3502Q4E ~/tests $ clang++ -stdlib=libc++ t1.cpp -o a.out
VogelEd@XLB3502Q4E ~/tests $ ./a.out value is 0

Note that the g++ library gets this right, but libc++ does not. Visual Studio 2019 also gives the correct answer.

Not a big deal, but I thought I'd post it.

Thanks,

Ed Vogel

edfvogel avatar Oct 12 '21 16:10 edfvogel