From 4e9788116f77668d7062e250ed9e1a4d429d924a Mon Sep 17 00:00:00 2001 From: kervala Date: Mon, 19 Dec 2016 15:50:54 +0100 Subject: [PATCH] Changed: Check return value of fwrite --- code/nel/src/misc/displayer.cpp | 25 +++++++++++++++---- .../src/r2/dmc/client_edition_module.cpp | 6 ++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/code/nel/src/misc/displayer.cpp b/code/nel/src/misc/displayer.cpp index 798a4f80a..8feaa9358 100644 --- a/code/nel/src/misc/displayer.cpp +++ b/code/nel/src/misc/displayer.cpp @@ -495,15 +495,30 @@ void CFileDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mes if (_NeedHeader) { const char *hs = HeaderString(); - fwrite (hs, strlen (hs), 1, _FilePointer); + + if (fwrite(hs, strlen(hs), 1, _FilePointer) != 1) + { + printf("Unable to write header: %s\n", hs); + } + _NeedHeader = false; } - if(!str.empty()) - fwrite (str.c_str(), str.size(), 1, _FilePointer); + if (!str.empty()) + { + if (fwrite(str.c_str(), str.size(), 1, _FilePointer) != 1) + { + printf("Unable to write string: %s\n", str.c_str()); + } + } - if(!args.CallstackAndLog.empty()) - fwrite (args.CallstackAndLog.c_str(), args.CallstackAndLog.size (), 1, _FilePointer); + if (!args.CallstackAndLog.empty()) + { + if (fwrite(args.CallstackAndLog.c_str(), args.CallstackAndLog.size(), 1, _FilePointer) != 1) + { + printf("Unable to write call stack: %s\n", args.CallstackAndLog.c_str()); + } + } fflush (_FilePointer); } diff --git a/code/ryzom/client/src/r2/dmc/client_edition_module.cpp b/code/ryzom/client/src/r2/dmc/client_edition_module.cpp index 37caebc3e..649996256 100644 --- a/code/ryzom/client/src/r2/dmc/client_edition_module.cpp +++ b/code/ryzom/client/src/r2/dmc/client_edition_module.cpp @@ -1652,7 +1652,11 @@ void CClientEditionModule::saveUserComponentFile(const std::string& filename, bo FILE* output = nlfopen(uncompressedName, "wb"); if (output) { - fwrite(component->UncompressedData, sizeof(char) , component->UncompressedDataLength, output); + if (fwrite(component->UncompressedData, sizeof(char), component->UncompressedDataLength, output) != component->UncompressedDataLength) + { + nlwarning("Unable to write %s", component->UncompressedData); + } + fclose(output); } }