diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-04-10 08:20:12 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-04-10 08:20:12 +0200 |
commit | 6a0b3e502f2a5889a01992edca2b458ed4c0e18c (patch) | |
tree | 795024bc4113b384e670f99b56e7ef1cac6503e9 /serialize | |
parent | dbdc15bf200d8fcade0fb0b48701e0366d03806c (diff) |
fix crash on empty save section
Diffstat (limited to 'serialize')
-rw-r--r-- | serialize/savegame.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/serialize/savegame.cpp b/serialize/savegame.cpp index eae4979a..b152fb31 100644 --- a/serialize/savegame.cpp +++ b/serialize/savegame.cpp @@ -700,10 +700,13 @@ template struct visitor_<writer, true>; void my_fwrite(FILE_raii& f, const buffer& buf, char(&errbuf)[128]) { - auto len = std::fwrite(&buf.data[0], buf.size, 1, f); - int error = errno; - if (len != 1) - fm_abort("fwrite: %s", get_error_string(errbuf, error).data()); + if (buf.size > 0) [[likely]] + { + auto len = std::fwrite(&buf.data[0], buf.size, 1, f); + int error = errno; + if (len != 1) + fm_abort("fwrite: %s", get_error_string(errbuf, error).data()); + } } } // namespace |