Skip to content

Commit

Permalink
Merge pull request #523 from zeux/ferrh
Browse files Browse the repository at this point in the history
Fix error handling in xml_document::save_file
  • Loading branch information
zeux authored Oct 9, 2022
2 parents 0cb4f02 + 444963e commit 86c9105
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/pugixml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5070,7 +5070,7 @@ PUGI__NS_BEGIN
xml_writer_file writer(file);
doc.save(writer, indent, flags, encoding);

return ferror(file) == 0;
return fflush(file) == 0 && ferror(file) == 0;
}

struct name_null_sentry
Expand Down Expand Up @@ -7423,15 +7423,15 @@ namespace pugi
using impl::auto_deleter; // MSVC7 workaround
auto_deleter<FILE> file(impl::open_file(path_, (flags & format_save_file_text) ? "w" : "wb"), impl::close_file);

return impl::save_file_impl(*this, file.data, indent, flags, encoding);
return impl::save_file_impl(*this, file.data, indent, flags, encoding) && fclose(file.release()) == 0;
}

PUGI__FN bool xml_document::save_file(const wchar_t* path_, const char_t* indent, unsigned int flags, xml_encoding encoding) const
{
using impl::auto_deleter; // MSVC7 workaround
auto_deleter<FILE> file(impl::open_file_wide(path_, (flags & format_save_file_text) ? L"w" : L"wb"), impl::close_file);

return impl::save_file_impl(*this, file.data, indent, flags, encoding);
return impl::save_file_impl(*this, file.data, indent, flags, encoding) && fclose(file.release()) == 0;
}

PUGI__FN xml_node xml_document::document_element() const
Expand Down

0 comments on commit 86c9105

Please sign in to comment.