Skip to content

Commit

Permalink
Fix cppcheck failed since after version 2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
25077667 authored and jserv committed Feb 21, 2024
1 parent 4627f69 commit 267cca7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
10 changes: 5 additions & 5 deletions report.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void set_verblevel(int level)
verblevel = level;
}

bool set_logfile(char *file_name)
bool set_logfile(const char *file_name)
{
logfile = fopen(file_name, "w");
return logfile != NULL;
Expand Down Expand Up @@ -161,7 +161,7 @@ void report_noreturn(int level, char *fmt, ...)
/* Functions denoting failures */

/* Need to be able to print without using malloc */
static void fail_fun(char *format, char *msg)
static void fail_fun(const char *format, const char *msg)
{
snprintf(fail_buf, sizeof(fail_buf), format, msg);
/* Tack on return */
Expand Down Expand Up @@ -209,7 +209,7 @@ static void check_exceed(size_t new_bytes)
}

/* Call malloc & exit if fails */
void *malloc_or_fail(size_t bytes, char *fun_name)
void *malloc_or_fail(size_t bytes, const char *fun_name)
{
check_exceed(bytes);
void *p = malloc(bytes);
Expand All @@ -228,7 +228,7 @@ void *malloc_or_fail(size_t bytes, char *fun_name)
}

/* Call calloc returns NULL & exit if fails */
void *calloc_or_fail(size_t cnt, size_t bytes, char *fun_name)
void *calloc_or_fail(size_t cnt, size_t bytes, const char *fun_name)
{
check_exceed(cnt * bytes);
void *p = calloc(cnt, bytes);
Expand All @@ -246,7 +246,7 @@ void *calloc_or_fail(size_t cnt, size_t bytes, char *fun_name)
return p;
}

char *strsave_or_fail(char *s, char *fun_name)
char *strsave_or_fail(const char *s, const char *fun_name)
{
if (!s)
return NULL;
Expand Down
8 changes: 4 additions & 4 deletions report.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ typedef enum { MSG_WARN, MSG_ERROR, MSG_FATAL, N_MSG } message_t;
/* Buffer sizes */
#define MAX_CHAR 512

bool set_logfile(char *file_name);
bool set_logfile(const char *file_name);

extern int verblevel;
void set_verblevel(int level);
Expand All @@ -27,13 +27,13 @@ void report(int verblevel, char *fmt, ...);
void report_noreturn(int verblevel, char *fmt, ...);

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

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

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

/* Free block, as from malloc, or strsave */
void free_block(void *b, size_t len);
Expand Down
5 changes: 4 additions & 1 deletion scripts/pre-commit.hook
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ CPPCHECK_suppresses="--inline-suppr harness.c \
--suppress=nullPointerRedundantCheck:report.c \
--suppress=nullPointerRedundantCheck:harness.c \
--suppress=nullPointer:queue.c \
--suppress=nullPointer:qtest.c"
--suppress=nullPointer:qtest.c \
--suppress=returnDanglingLifetime:report.c \
--suppress=constParameterCallback:console.c \
--suppress=constParameterPointer:console.c"
CPPCHECK_OPTS="-I. --enable=all --error-exitcode=1 --force $CPPCHECK_suppresses $CPPCHECK_unmatched ."

RETURN=0
Expand Down

0 comments on commit 267cca7

Please sign in to comment.