From 426c621b32e70555780dda0c958022415f29dfe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 21 Aug 2024 11:10:03 +0200 Subject: [PATCH] Fix #13026 (Fix Coverity issues) (#6710) --- lib/checkunusedvar.cpp | 2 +- lib/path.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index f22987b77b1..755b77517c7 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -1595,7 +1595,7 @@ bool CheckUnusedVar::isRecordTypeWithoutSideEffects(const Type* type) continue; // ignore default/deleted constructors const bool emptyBody = (f.functionScope && Token::simpleMatch(f.functionScope->bodyStart, "{ }")); - const Token* nextToken = f.argDef->link(); + const Token* nextToken = f.argDef ? f.argDef->link() : nullptr; if (Token::simpleMatch(nextToken, ") :")) { // validating initialization list nextToken = nextToken->next(); // goto ":" diff --git a/lib/path.cpp b/lib/path.cpp index f7943980924..8b0b75c8ca0 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -164,7 +164,8 @@ std::string Path::getCurrentExecutablePath(const char* fallback) #else // Linux "/proc/self/exe"; #endif - success = (readlink(procPath, buf, sizeof(buf)) != -1); + // readlink does not null-terminate the string if the buffer is too small, therefore write bufsize - 1 + success = (readlink(procPath, buf, sizeof(buf) - 1) != -1); #endif return success ? std::string(buf) : std::string(fallback); }