Skip to content

Commit 267cca7

Browse files
scc-twjserv
authored andcommitted
Fix cppcheck failed since after version 2.9
Close #153
1 parent 4627f69 commit 267cca7

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

Diff for: report.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void set_verblevel(int level)
4545
verblevel = level;
4646
}
4747

48-
bool set_logfile(char *file_name)
48+
bool set_logfile(const char *file_name)
4949
{
5050
logfile = fopen(file_name, "w");
5151
return logfile != NULL;
@@ -161,7 +161,7 @@ void report_noreturn(int level, char *fmt, ...)
161161
/* Functions denoting failures */
162162

163163
/* Need to be able to print without using malloc */
164-
static void fail_fun(char *format, char *msg)
164+
static void fail_fun(const char *format, const char *msg)
165165
{
166166
snprintf(fail_buf, sizeof(fail_buf), format, msg);
167167
/* Tack on return */
@@ -209,7 +209,7 @@ static void check_exceed(size_t new_bytes)
209209
}
210210

211211
/* Call malloc & exit if fails */
212-
void *malloc_or_fail(size_t bytes, char *fun_name)
212+
void *malloc_or_fail(size_t bytes, const char *fun_name)
213213
{
214214
check_exceed(bytes);
215215
void *p = malloc(bytes);
@@ -228,7 +228,7 @@ void *malloc_or_fail(size_t bytes, char *fun_name)
228228
}
229229

230230
/* Call calloc returns NULL & exit if fails */
231-
void *calloc_or_fail(size_t cnt, size_t bytes, char *fun_name)
231+
void *calloc_or_fail(size_t cnt, size_t bytes, const char *fun_name)
232232
{
233233
check_exceed(cnt * bytes);
234234
void *p = calloc(cnt, bytes);
@@ -246,7 +246,7 @@ void *calloc_or_fail(size_t cnt, size_t bytes, char *fun_name)
246246
return p;
247247
}
248248

249-
char *strsave_or_fail(char *s, char *fun_name)
249+
char *strsave_or_fail(const char *s, const char *fun_name)
250250
{
251251
if (!s)
252252
return NULL;

Diff for: report.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ typedef enum { MSG_WARN, MSG_ERROR, MSG_FATAL, N_MSG } message_t;
1212
/* Buffer sizes */
1313
#define MAX_CHAR 512
1414

15-
bool set_logfile(char *file_name);
15+
bool set_logfile(const char *file_name);
1616

1717
extern int verblevel;
1818
void set_verblevel(int level);
@@ -27,13 +27,13 @@ void report(int verblevel, char *fmt, ...);
2727
void report_noreturn(int verblevel, char *fmt, ...);
2828

2929
/* Attempt to call malloc. Fail when returns NULL */
30-
void *malloc_or_fail(size_t bytes, char *fun_name);
30+
void *malloc_or_fail(size_t bytes, const char *fun_name);
3131

3232
/* Attempt to call calloc. Fail when returns NULL */
33-
void *calloc_or_fail(size_t cnt, size_t bytes, char *fun_name);
33+
void *calloc_or_fail(size_t cnt, size_t bytes, const char *fun_name);
3434

3535
/* Attempt to save string. Fail when malloc returns NULL */
36-
char *strsave_or_fail(char *s, char *fun_name);
36+
char *strsave_or_fail(const char *s, const char *fun_name);
3737

3838
/* Free block, as from malloc, or strsave */
3939
void free_block(void *b, size_t len);

Diff for: scripts/pre-commit.hook

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ CPPCHECK_suppresses="--inline-suppr harness.c \
1313
--suppress=nullPointerRedundantCheck:report.c \
1414
--suppress=nullPointerRedundantCheck:harness.c \
1515
--suppress=nullPointer:queue.c \
16-
--suppress=nullPointer:qtest.c"
16+
--suppress=nullPointer:qtest.c \
17+
--suppress=returnDanglingLifetime:report.c \
18+
--suppress=constParameterCallback:console.c \
19+
--suppress=constParameterPointer:console.c"
1720
CPPCHECK_OPTS="-I. --enable=all --error-exitcode=1 --force $CPPCHECK_suppresses $CPPCHECK_unmatched ."
1821

1922
RETURN=0

0 commit comments

Comments
 (0)