Skip to content

Commit f3a4def

Browse files
authored
[libcxx][ios] initialize __fill_val_ in _FillHelper (#110279)
This is a small fix to #89305. In the `__init` function of `_FillHelper`, `__fill_val_` was left uninitialized. This worked for the implementation in the PR because we always checked `__set_` before trying to read it, and would initialize if it was unset. However it turns out in earlier versions of the header (at least on AIX which followed this path), we do a read of `__fill_val_` even if `__set_` was false before initializing, to check if it matched the sentinel value, so this causes undesired behaviour and UB.
1 parent 8b47711 commit f3a4def

File tree

1 file changed

+4
-1
lines changed
  • libcxx/include

1 file changed

+4
-1
lines changed

libcxx/include/ios

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,10 @@ template <class _Traits>
524524
// Attribute 'packed' is used to keep the layout compatible with the previous
525525
// definition of the '__fill_' and '_set_' pair in basic_ios on AIX & z/OS.
526526
struct _LIBCPP_PACKED _FillHelper {
527-
_LIBCPP_HIDE_FROM_ABI void __init() { __set_ = false; }
527+
_LIBCPP_HIDE_FROM_ABI void __init() {
528+
__set_ = false;
529+
__fill_val_ = _Traits::eof();
530+
}
528531
_LIBCPP_HIDE_FROM_ABI _FillHelper& operator=(typename _Traits::int_type __x) {
529532
__set_ = true;
530533
__fill_val_ = __x;

0 commit comments

Comments
 (0)