diff --git a/src/Makefile.in b/src/Makefile.in index 8bc56c60..b421cefa 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -80,9 +80,6 @@ install-stripped: install clean: rm -f *.o *~ core *.bak $(PROGS) -cppcheck: - cppcheck --force --enable=all --suppress=variableScope --suppress=ConfigurationNotChecked *.c - clobber: rm -f *.o *~ remind rem2ps test.out core *.bak @@ -92,6 +89,9 @@ depend: # The next targets are not very useful to you. I use them to build # distributions, etc. +cppcheck: + cppcheck -j`nproc` --force --enable=all --suppress=ConfigurationNotChecked --suppress=unmatchedSuppression --suppress=variableScope --inline-suppr . + # Build a tar file based on all files checked into git. distro: cd .. && git archive --worktree-attributes --format=tar --prefix=remind-$(VERSION)/ HEAD > src/remind-$(VERSION).tar diff --git a/src/calendar.c b/src/calendar.c index 7b6cc3ef..60f90fc7 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -1041,7 +1041,7 @@ static void DoCalendarOneMonth(void) printf("\"entries\":[\n"); } } - while (WriteCalendarRow()) continue; + while (WriteCalendarRow()) /* continue */; if (PsCal == PSCAL_LEVEL1) { printf("%s\n", PSEND); diff --git a/src/dosubst.c b/src/dosubst.c index cb61312b..4fc96685 100644 --- a/src/dosubst.c +++ b/src/dosubst.c @@ -50,7 +50,7 @@ int DoSubst(ParsePtr p, DynamicBuffer *dbuf, Trigger *t, TimeTrig *tt, int dse, int err, done; int c; int d, m, y; - int tim = tt->ttime; + int tim = NO_TIME; int h, min, hh, ch, cmin, chh; int i; char const *pm, *cpm; @@ -72,6 +72,9 @@ int DoSubst(ParsePtr p, DynamicBuffer *dbuf, Trigger *t, TimeTrig *tt, int dse, FromDSE(dse, &y, &m, &d); + if (tt) { + tim = tt->ttime; + } if (tim == NO_TIME) tim = curtime; tdiff = tim - curtime; adiff = ABS(tdiff); diff --git a/src/expr.h b/src/expr.h index 33c37b24..2c75dc4e 100644 --- a/src/expr.h +++ b/src/expr.h @@ -45,8 +45,10 @@ else \ (op) = OpStack[--OpStackPtr] #define PushValStack(val) \ -if (ValStackPtr >= VAL_STACK_SIZE) \ -return E_VA_STK_OVER; \ +if (ValStackPtr >= VAL_STACK_SIZE) { \ + DestroyValue(val); \ + return E_VA_STK_OVER; \ +} \ else \ ValStack[ValStackPtr++] = (val) diff --git a/src/files.c b/src/files.c index 7e224f47..37995d15 100644 --- a/src/files.c +++ b/src/files.c @@ -42,8 +42,8 @@ /* Convenient macros for closing files */ -#define FCLOSE(fp) (((fp)&&((fp)!=stdin)) ? (fclose(fp),(fp)=NULL) : ((fp)=NULL)) -#define PCLOSE(fp) (((fp)&&((fp)!=stdin)) ? (pclose(fp),(fp)=NULL) : ((fp)=NULL)) +#define FCLOSE(fp) ((((fp)!=stdin)) ? (fclose(fp),(fp)=NULL) : ((fp)=NULL)) +#define PCLOSE(fp) ((((fp)!=stdin)) ? (pclose(fp),(fp)=NULL) : ((fp)=NULL)) /* Define the structures needed by the file caching system */ typedef struct cache { diff --git a/src/globals.h b/src/globals.h index 71d99581..7835920d 100644 --- a/src/globals.h +++ b/src/globals.h @@ -39,7 +39,7 @@ EXTERN FILE *ErrFp; #define IsLeapYear(y) (((y) % 4) ? 0 : ((!((y) % 100) && ((y) % 400)) ? 0 : 1 )) #define DaysInMonth(m, y) ((m) != 1 ? MonthDays[m] : 28 + IsLeapYear(y)) -#define DestroyValue(x) (void) (((x).type == STR_TYPE && (x).v.str) ? (free((x).v.str),(x).v.str = NULL,(x).type = ERR_TYPE) : 0) +#define DestroyValue(x) do { if ((x).type == STR_TYPE && (x).v.str) { free((x).v.str); (x).v.str = NULL; } (x).type = ERR_TYPE; } while (0) EXTERN int DSEToday; EXTERN int RealToday; diff --git a/src/init.c b/src/init.c index 17ce5efc..b88d843e 100644 --- a/src/init.c +++ b/src/init.c @@ -1004,7 +1004,7 @@ guess_terminal_background(int *r, int *g, int *b) { int ttyfd; struct pollfd p; - int rr, gg, bb; + unsigned int rr, gg, bb; char buf[128]; int n; @@ -1070,9 +1070,9 @@ guess_terminal_background(int *r, int *g, int *b) /* Couldn't scan color codes */ return; } - *r = (rr >> 8) & 255; - *g = (gg >> 8) & 255; - *b = (bb >> 8) & 255; + *r = (int) ((rr >> 8) & 255); + *g = (int) ((gg >> 8) & 255); + *b = (int) ((bb >> 8) & 255); } static struct termios orig_termios; diff --git a/src/main.c b/src/main.c index 260b0434..88895f11 100644 --- a/src/main.c +++ b/src/main.c @@ -590,8 +590,8 @@ int EvaluateExpr(ParsePtr p, Value *v) int r; if (p->isnested) return E_PARSE_ERR; /* Can't nest expressions */ - while (isempty(*p->pos)) (p->pos)++; if (!p->pos) return E_PARSE_ERR; /* Missing expression */ + while (isempty(*p->pos)) (p->pos)++; if (*p->pos == BEG_OF_EXPR) { (p->pos)++; bracketed = 1; @@ -1690,9 +1690,7 @@ System(char const *cmd, int is_queued) } } else { /* In the parent */ - while (waitpid(kid, &status, 0) != kid) { - continue; - } + while (waitpid(kid, &status, 0) != kid) /* continue */ ; return; } } diff --git a/src/omit.c b/src/omit.c index 551514f9..854dcf7d 100644 --- a/src/omit.c +++ b/src/omit.c @@ -22,7 +22,7 @@ #include "err.h" #include "expr.h" -static int BexistsIntArray (int array[], int num, int key); +static int BexistsIntArray (int const array[], int num, int key); static void InsertIntoSortedArray (int *array, int num, int key); /* Arrays for the global omits */ @@ -251,7 +251,7 @@ int IsOmitted(int dse, int localomit, char const *omitfunc, int *omit) /* element is found, 0 otherwise. */ /* */ /***************************************************************/ -static int BexistsIntArray(int array[], int num, int key) +static int BexistsIntArray(int const array[], int num, int key) { int top=num-1, bot=0, mid; diff --git a/src/protos.h b/src/protos.h index bfd68243..e47cdc47 100644 --- a/src/protos.h +++ b/src/protos.h @@ -108,7 +108,7 @@ char *StrDup (char const *s); int StrCmpi (char const *s1, char const *s2); Var *FindVar (char const *str, int create); int DeleteVar (char const *str); -int SetVar (char const *str, Value *val); +int SetVar (char const *str, Value const *val); int GetVarValue (char const *str, Value *val, Var *locals, ParsePtr p); int DoSet (Parser *p); int DoUnset (Parser *p); diff --git a/src/trigger.c b/src/trigger.c index 2fba5ee8..9119dd78 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -244,6 +244,7 @@ static int NextSimpleTrig(int startdate, Trigger *trig, int *err) case GOT_WD+GOT_MON+GOT_YR: if (y > trig->y || (y == trig->y && m > trig->m)) return -1; + /* cppcheck-suppress knownConditionTrueFalse */ if (trig->y > y || (trig->y == y && trig->m > m)) { j = DSE(trig->y, trig->m, 1); ADVANCE_TO_WD(j, trig->wd); diff --git a/src/var.c b/src/var.c index 140f2715..6a477bcd 100644 --- a/src/var.c +++ b/src/var.c @@ -480,7 +480,7 @@ int DeleteVar(char const *str) /* Set the indicate variable to the specified value. */ /* */ /***************************************************************/ -int SetVar(char const *str, Value *val) +int SetVar(char const *str, Value const *val) { Var *v = FindVar(str, 1);