From d499dfac1c4dacf97d4bfae9285595c76ab2f01c Mon Sep 17 00:00:00 2001 From: kevin Date: Tue, 14 Nov 2023 07:52:15 -0500 Subject: [PATCH] cwFile.cpp : Added guard to not write if bufByteCnt is 0. --- cwFile.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cwFile.cpp b/cwFile.cpp index 51a5642..e8a35bd 100644 --- a/cwFile.cpp +++ b/cwFile.cpp @@ -251,11 +251,14 @@ cw::rc_t cw::file::write( handle_t h, const void* buf, unsigned bufByteCnt ) if( p->lastRC != kOkRC ) return p->lastRC; - - errno = 0; - if( fwrite(buf,bufByteCnt,1,p->fp) != 1 ) - return p->lastRC = cwLogSysError(kWriteFailRC,errno,"File write failed on '%s'.", cwStringNullGuard(p->fnStr)); + if( bufByteCnt ) + { + errno = 0; + if( fwrite(buf,bufByteCnt,1,p->fp) != 1 ) + return p->lastRC = cwLogSysError(kWriteFailRC,errno,"File write failed on '%s'.", cwStringNullGuard(p->fnStr)); + } + return kOkRC; }