From 65f57b875f164ed693cdacd1125a64de7f98a515 Mon Sep 17 00:00:00 2001 From: YongDo-Hyun Date: Sat, 27 Dec 2025 16:24:03 +0300 Subject: fix: correct exception handling in ozlibstream::close method Signed-off-by: YongDo-Hyun --- src/io/ozlibstream.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/io/ozlibstream.cpp b/src/io/ozlibstream.cpp index ba6187645c..d1cb25dac0 100644 --- a/src/io/ozlibstream.cpp +++ b/src/io/ozlibstream.cpp @@ -113,15 +113,14 @@ void ozlibstream::close() // `setstate` to throw an `ios_base::failure` which would replace // the original exception. Temporarily disable exceptions on this // stream, set the `badbit`, then restore the exception mask. + std::ios_base::iostate old_ex = exceptions(); + exceptions(std::ios_base::goodbit); + setstate(std::ios_base::badbit); try { - exceptions(std::ios_base::goodbit); - setstate(std::ios_base::badbit); - } - catch(...) { - // If anything unexpected happens while setting state, swallow - // it — we don't want this to throw here. + exceptions(old_ex); + } catch (...) { + // If anything unexpected happens while restoring the exception mask, + // swallow it — we don't want this to throw here. } - exceptions(old_ex); -} - + } } -- cgit 0.0.5-2-1-g0f52