Skip to content

Commit 4e96470

Browse files
wangzhi16xiaoxiang781216
authored andcommitted
Solve static checking problems.
The code detection tool thinks that when if (pos != NULL) is false, that is, when pos is null, the strchr(pos, ',') operation will be performed on pos, causing a null pointer error, for example: line 226: if (*pos != '\0') when pos is null. line 236: pos = strchrnul(pos, ','); Dereference of a null pointer. However, this will not happen, because the configuration condition(line 234) will be judged first. If pos is null, line 236 will not be executed. SOLUTION: Use strchrnul to replace strchr. Even if no characters are matched, a null pointer will not be returned, thus avoiding incorrect judgment by code detection tools. Signed-off-by: wangzhi16 <[email protected]>
1 parent 2ca8f1c commit 4e96470

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

system/critmon/critmon.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ static int critmon_process_directory(FAR struct dirent *entryp)
222222

223223
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_PREEMPTION >= 0
224224
maxpreemp = pos;
225-
pos = strchr(pos, ',');
226-
if (pos != NULL)
225+
pos = strchrnul(pos, ',');
226+
if (*pos != '\0')
227227
{
228228
*pos++ = '\0';
229229
}
@@ -233,8 +233,8 @@ static int critmon_process_directory(FAR struct dirent *entryp)
233233

234234
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0
235235
maxcrit = pos;
236-
pos = strchr(pos, ',');
237-
if (pos != NULL)
236+
pos = strchrnul(pos, ',');
237+
if (*pos != '\0')
238238
{
239239
*pos++ = '\0';
240240
}
@@ -244,15 +244,15 @@ static int critmon_process_directory(FAR struct dirent *entryp)
244244

245245
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_THREAD >= 0
246246
maxrun = pos;
247-
pos = strchr(pos, ',');
248-
if (pos != NULL)
247+
pos = strchrnul(pos, ',');
248+
if (*pos != '\0')
249249
{
250250
*pos++ = '\0';
251251
}
252252

253253
runtime = pos;
254-
pos = strchr(pos, ',');
255-
if (pos != NULL)
254+
pos = strchrnul(pos, ',');
255+
if (*pos != '\0')
256256
{
257257
*pos++ = '\0';
258258
}
@@ -362,16 +362,16 @@ static void critmon_global_crit(void)
362362

363363
pos = critmon_isolate_value(g_critmon.line);
364364
cpu = pos;
365-
pos = strchr(pos, ',');
366-
if (pos != NULL)
365+
pos = strchrnul(pos, ',');
366+
if (*pos != '\0')
367367
{
368368
*pos++ = '\0';
369369
}
370370

371371
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_PREEMPTION >= 0
372372
maxpreemp = pos;
373-
pos = strchr(pos, ',');
374-
if (pos != NULL)
373+
pos = strchrnul(pos, ',');
374+
if (*pos != '\0')
375375
{
376376
*pos++ = '\0';
377377
}
@@ -381,8 +381,8 @@ static void critmon_global_crit(void)
381381

382382
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0
383383
maxcrit = pos;
384-
pos = strchr(pos, ',');
385-
if (pos != NULL)
384+
pos = strchrnul(pos, ',');
385+
if (*pos != '\0')
386386
{
387387
*pos++ = '\0';
388388
}

0 commit comments

Comments
 (0)