From e3f3f85391a875101fbf0bea47fb5121ea313eae Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 15 Apr 2024 09:49:41 +0200 Subject: [PATCH] [coverity] 1543117 Argument cannot be negative --- winpr/libwinpr/file/file.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/winpr/libwinpr/file/file.c b/winpr/libwinpr/file/file.c index 648455dcb..a016beb13 100644 --- a/winpr/libwinpr/file/file.c +++ b/winpr/libwinpr/file/file.c @@ -96,14 +96,15 @@ static BOOL FileCloseHandle(HANDLE handle) static BOOL FileSetEndOfFile(HANDLE hFile) { WINPR_FILE* pFile = (WINPR_FILE*)hFile; - INT64 size = 0; if (!hFile) return FALSE; - size = _ftelli64(pFile->fp); + const INT64 size = _ftelli64(pFile->fp); + if (size < 0) + return FALSE; - if (ftruncate(fileno(pFile->fp), size) < 0) + if (ftruncate(fileno(pFile->fp), (off_t)size) < 0) { char ebuffer[256] = { 0 }; WLog_ERR(TAG, "ftruncate %s failed with %s [0x%08X]", pFile->lpFileName,