summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYongDo-Hyun <froster12@naver.com>2025-12-27 16:38:59 +0300
committerMehmet Samet Duman <yongdohyun@projecttick.org>2026-03-27 19:57:09 +0300
commitbf3635fd75c9afd736c826b1cc89e3d07afad887 (patch)
tree36fc5e879905496e60ae50629aa34d884508ebbb
parent65f57b875f164ed693cdacd1125a64de7f98a515 (diff)
downloadProject-Tick-bf3635fd75c9afd736c826b1cc89e3d07afad887.tar.gz
Project-Tick-bf3635fd75c9afd736c826b1cc89e3d07afad887.zip
fix: improve exception handling in ozlibstream::close method to prevent masking errors
Signed-off-by: YongDo-Hyun <froster12@naver.com>
-rw-r--r--src/io/ozlibstream.cpp23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/io/ozlibstream.cpp b/src/io/ozlibstream.cpp
index d1cb25dac0..c62f58dace 100644
--- a/src/io/ozlibstream.cpp
+++ b/src/io/ozlibstream.cpp
@@ -97,30 +97,31 @@ void ozlibstream::close()
{
// Capture the exception mask so we can restore it if close() fails.
std::ios_base::iostate old_ex = exceptions();
- bool close_failed = false;
try
{
buf.close();
+ return;
}
catch(...)
{
- close_failed = true;
+ // fall through to mark the stream as bad
}
- if(!close_failed)
- return;
// Setting the stream state while exceptions are enabled may cause
// `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(old_ex);
- } catch (...) {
- // If anything unexpected happens while restoring the exception mask,
- // swallow it — we don't want this to throw here.
+ try
+ {
+ exceptions(old_ex);
+ }
+ catch(...)
+ {
+ // If anything unexpected happens while restoring the exception mask,
+ // swallow it — we don't want this to throw here.
}
- }
}
+
+} // namespace zlib