Skip to content

Commit 14c24de

Browse files
authored
fixed #12526 - corrected bailout in valueFlowConditionExpressions() / restored valueFlowBailoutIncompleteVar in daca (#6153)
The bailout was moved out of an inner loop in a3617fe but it kept the previous `break`. This caused it to bail out completely instead of just skipping the function. References for the added defines: https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-createeventexa#parameters https://learn.microsoft.com/en-us/windows/win32/secauthz/well-known-sids
1 parent 69037c9 commit 14c24de

16 files changed

Lines changed: 118 additions & 24 deletions

cfg/windows.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4907,6 +4907,8 @@ HFONT CreateFont(
49074907
<not-bool/>
49084908
</arg>
49094909
</function>
4910+
<define name="CREATE_EVENT_INITIAL_SET" value="0x00000002"/>
4911+
<define name="CREATE_EVENT_MANUAL_RESET" value="0x00000001"/>
49104912
<!--HANDLE WINAPI OpenEvent(
49114913
_In_ DWORD dwDesiredAccess,
49124914
_In_ BOOL bInheritHandle,
@@ -5453,6 +5455,17 @@ HFONT CreateFont(
54535455
<not-null/>
54545456
</arg>
54555457
</function>
5458+
<define name="SECURITY_NULL_SID_AUTHORITY" value="0"/>
5459+
<define name="SECURITY_WORLD_SID_AUTHORITY" value="1"/>
5460+
<define name="SECURITY_LOCAL_SID_AUTHORITY" value="2"/>
5461+
<define name="SECURITY_CREATOR_SID_AUTHORITY" value="3"/>
5462+
<define name="SECURITY_NT_AUTHORITY" value="5"/>
5463+
<define name="SECURITY_NULL_RID" value="0"/>
5464+
<define name="SECURITY_WORLD_RID" value="0"/>
5465+
<define name="SECURITY_LOCAL_RID" value="0"/>
5466+
<define name="SECURITY_LOCAL_LOGON_RID" value="1"/>
5467+
<define name="SECURITY_CREATOR_OWNER_RID" value="0"/>
5468+
<define name="SECURITY_CREATOR_GROUP_RID" value="1"/>
54565469
<!--PVOID WINAPI FreeSid(_In_ PSID pSid);-->
54575470
<function name="FreeSid">
54585471
<noreturn>false</noreturn>

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4251,7 +4251,7 @@ static bool setVarIdParseDeclaration(Token** tok, const VariableMap& variableMap
42514251
bracket = true;
42524252
} else if (tok2->str() == "::") {
42534253
singleNameCount = 0;
4254-
} else if (tok2->str() != "*" && tok2->str() != "::" && tok2->str() != "...") {
4254+
} else if (tok2->str() != "*" && tok2->str() != "...") {
42554255
break;
42564256
}
42574257
tok2 = tok2->next();

lib/valueflow.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5334,16 +5334,19 @@ static const Scope* getLoopScope(const Token* tok)
53345334
//
53355335
static void valueFlowConditionExpressions(const TokenList &tokenlist, const SymbolDatabase& symboldatabase, ErrorLogger *errorLogger, const Settings &settings)
53365336
{
5337-
if (settings.checkLevel == Settings::CheckLevel::normal)
5337+
if (!settings.daca && (settings.checkLevel == Settings::CheckLevel::normal))
53385338
return;
53395339

53405340
for (const Scope * scope : symboldatabase.functionScopes) {
53415341
if (const Token* incompleteTok = findIncompleteVar(scope->bodyStart, scope->bodyEnd)) {
53425342
if (settings.debugwarnings)
53435343
bailoutIncompleteVar(tokenlist, errorLogger, incompleteTok, "Skipping function due to incomplete variable " + incompleteTok->str());
5344-
break;
5344+
continue;
53455345
}
53465346

5347+
if (settings.daca && (settings.checkLevel == Settings::CheckLevel::normal))
5348+
continue;
5349+
53475350
for (Token* tok = const_cast<Token*>(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) {
53485351
if (!Token::simpleMatch(tok, "if ("))
53495352
continue;

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ if (BUILD_TESTS)
132132
--suppress=valueFlowBailout
133133
--suppress=purgedConfiguration
134134
--suppress=unmatchedSuppression
135+
--suppress=checkersReport
135136
${CMAKE_CURRENT_SOURCE_DIR}/cfg/${CFG_TEST}
136137
)
137138
endif()

test/cfg/gnu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ void memleak_xmalloc()
387387

388388
void memleak_mmap()
389389
{
390+
// cppcheck-suppress valueFlowBailoutIncompleteVar
390391
const void * p_mmap = mmap(NULL, 1, PROT_NONE, MAP_ANONYMOUS | MAP_SHARED, -1, 0);
391392
printf("%p", p_mmap);
392393
// cppcheck-suppress memleak
@@ -466,6 +467,7 @@ int nullPointer_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)
466467
// Remove (deregister) the target file descriptor fd from the
467468
// epoll instance referred to by epfd. The event is ignored and
468469
// can be NULL.
470+
// cppcheck-suppress valueFlowBailoutIncompleteVar
469471
return epoll_ctl(epfd, EPOLL_CTL_DEL, fd, NULL);
470472
}
471473
#endif

test/cfg/googletest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ TEST(test_cppcheck, cppcheck)
5050
// #9964 - avoid compareBoolExpressionWithInt false positive
5151
TEST(Test, assert_false_fp)
5252
{
53+
// cppcheck-suppress valueFlowBailoutIncompleteVar
5354
ASSERT_FALSE(errno < 0);
5455
}
5556

@@ -73,6 +74,7 @@ TEST(Test, warning_in_assert_macros)
7374
// cppcheck-suppress duplicateExpression
7475
ASSERT_GE(i, i);
7576

77+
// cppcheck-suppress valueFlowBailoutIncompleteVar
7678
unsigned int u = errno;
7779
// cppcheck-suppress [unsignedPositive]
7880
ASSERT_GE(u, 0);

test/cfg/gtk.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ void g_new0_test()
302302
int b;
303303
};
304304
// valid
305+
// cppcheck-suppress valueFlowBailoutIncompleteVar
305306
struct a * pNew1 = g_new0(struct a, 5);
306307
printf("%p", pNew1);
307308
g_free(pNew1);
@@ -320,6 +321,7 @@ void g_try_new_test()
320321
int b;
321322
};
322323
// valid
324+
// cppcheck-suppress valueFlowBailoutIncompleteVar
323325
struct a * pNew1 = g_try_new(struct a, 5);
324326
printf("%p", pNew1);
325327
g_free(pNew1);
@@ -337,6 +339,7 @@ void g_try_new0_test()
337339
int b;
338340
};
339341
// valid
342+
// cppcheck-suppress valueFlowBailoutIncompleteVar
340343
struct a * pNew1 = g_try_new0(struct a, 5);
341344
printf("%p", pNew1);
342345
g_free(pNew1);
@@ -354,7 +357,7 @@ void g_renew_test()
354357
struct a {
355358
int b;
356359
};
357-
// cppcheck-suppress leakReturnValNotUsed
360+
// cppcheck-suppress [leakReturnValNotUsed,valueFlowBailoutIncompleteVar]
358361
g_renew(struct a, NULL, 1);
359362

360363
struct a * pNew = g_new(struct a, 1);
@@ -369,7 +372,7 @@ void g_try_renew_test()
369372
struct a {
370373
int b;
371374
};
372-
// cppcheck-suppress leakReturnValNotUsed
375+
// cppcheck-suppress [leakReturnValNotUsed,valueFlowBailoutIncompleteVar]
373376
g_try_renew(struct a, NULL, 1);
374377

375378
struct a * pNew = g_try_new(struct a, 1);

test/cfg/opencv2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ void ignoredReturnValue()
4141
void memleak()
4242
{
4343
const char * pBuf = (char *)cv::fastMalloc(1000); // cppcheck-suppress cstyleCast
44-
std::cout << pBuf;
44+
std::cout << pBuf; // cppcheck-suppress valueFlowBailoutIncompleteVar
4545
// cppcheck-suppress memleak
4646
}

test/cfg/posix.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,7 @@ void * memleak_mmap2() // #8327
10621062
void memleak_getline() { // #11043
10631063
char *line = NULL;
10641064
size_t size = 0;
1065+
// cppcheck-suppress valueFlowBailoutIncompleteVar
10651066
getline(&line, &size, stdin);
10661067
// cppcheck-suppress memleak
10671068
line = NULL;
@@ -1082,6 +1083,7 @@ void memleak_getline_array(FILE* stream) { // #12498
10821083
void memleak_getdelim(int delim) {
10831084
char *line = NULL;
10841085
size_t size = 0;
1086+
// cppcheck-suppress valueFlowBailoutIncompleteVar
10851087
getdelim(&line, &size, delim, stdin);
10861088
// cppcheck-suppress memleak
10871089
line = NULL;
@@ -1101,6 +1103,7 @@ void memleak_getdelim_array(FILE* stream, int delim) {
11011103

11021104
void * identicalCondition_mmap(int fd, size_t size) // #9940
11031105
{
1106+
// cppcheck-suppress valueFlowBailoutIncompleteVar
11041107
void* buffer = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
11051108
if (buffer == MAP_FAILED) {
11061109
return NULL;
@@ -1113,6 +1116,7 @@ int munmap_no_double_free(int tofd, // #11396
11131116
size_t len)
11141117
{
11151118
int rc;
1119+
// cppcheck-suppress valueFlowBailoutIncompleteVar
11161120
const void* fptr = mmap(NULL,len,PROT_READ|PROT_WRITE,MAP_SHARED,fromfd,(off_t)0);
11171121
if (fptr == MAP_FAILED) {
11181122
return -1;
@@ -1147,6 +1151,7 @@ void resourceLeak_fdopen(int fd)
11471151

11481152
void resourceLeak_fdopen2(const char* fn) // #2767
11491153
{
1154+
// cppcheck-suppress valueFlowBailoutIncompleteVar
11501155
int fi = open(fn, O_RDONLY);
11511156
FILE* fd = fdopen(fi, "r");
11521157
fclose(fd);
@@ -1193,14 +1198,14 @@ void resourceLeak_socket(void)
11931198

11941199
void resourceLeak_open1(void)
11951200
{
1196-
// cppcheck-suppress unreadVariable
1201+
// cppcheck-suppress [unreadVariable,valueFlowBailoutIncompleteVar]
11971202
int fd = open("file", O_RDWR | O_CREAT);
11981203
// cppcheck-suppress resourceLeak
11991204
}
12001205

12011206
void resourceLeak_open2(void)
12021207
{
1203-
// cppcheck-suppress unreadVariable
1208+
// cppcheck-suppress [unreadVariable,valueFlowBailoutIncompleteVar]
12041209
int fd = open("file", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
12051210
// cppcheck-suppress resourceLeak
12061211
}
@@ -1213,6 +1218,7 @@ void noleak(int x, int y, int z)
12131218
closedir(p2);
12141219
int s = socket(AF_INET,SOCK_STREAM,0);
12151220
close(s);
1221+
// cppcheck-suppress valueFlowBailoutIncompleteVar
12161222
int fd1 = open("a", O_RDWR | O_CREAT);
12171223
close(fd1);
12181224
int fd2 = open("a", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
@@ -1357,7 +1363,7 @@ void timet_h(const struct timespec* ptp1)
13571363
clockid_t clk_id1, clk_id2, clk_id3;
13581364
// cppcheck-suppress constVariablePointer
13591365
struct timespec* ptp;
1360-
// cppcheck-suppress uninitvar
1366+
// cppcheck-suppress [uninitvar,valueFlowBailoutIncompleteVar]
13611367
clock_settime(CLOCK_REALTIME, ptp);
13621368
// cppcheck-suppress uninitvar
13631369
clock_settime(clk_id1, ptp);

test/cfg/qt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ void validCode(int * pIntPtr, QString & qstrArg, double d)
576576

577577
printf(QT_TR_NOOP("Hi"));
578578

579-
// cppcheck-suppress checkLibraryFunction
579+
// cppcheck-suppress [checkLibraryFunction,valueFlowBailoutIncompleteVar]
580580
Q_DECLARE_LOGGING_CATEGORY(logging_category_test);
581581
QT_FORWARD_DECLARE_CLASS(forwardDeclaredClass);
582582
QT_FORWARD_DECLARE_STRUCT(forwardDeclaredStruct);

0 commit comments

Comments
 (0)