From c3ab2a15cfee8a5ac3c459cb287d4c996034b1b8 Mon Sep 17 00:00:00 2001 From: Dianne Skoll Date: Mon, 21 Jul 2025 17:44:13 -0400 Subject: [PATCH] Add some consts as recommended by make cppcheck. --- src/dedupe.c | 8 ++++---- src/files.c | 8 ++++---- src/hashtab.c | 4 ++-- src/hashtab.h | 4 ++-- src/init.c | 2 +- src/moon.c | 2 +- src/token.c | 2 +- src/trans.c | 8 ++++---- src/userfns.c | 6 +++--- src/utils.c | 2 +- src/var.c | 8 ++++---- 11 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/dedupe.c b/src/dedupe.c index 4f8638a2..1b28f41e 100644 --- a/src/dedupe.c +++ b/src/dedupe.c @@ -30,7 +30,7 @@ static hash_table DedupeTable; static unsigned int DedupeHashFunc(void *x) { - DedupeEntry *e = (DedupeEntry *) x; + DedupeEntry const *e = (DedupeEntry const *) x; unsigned int hashval = (unsigned int) e->trigger_date; if (e->trigger_time != NO_TIME) { hashval += (unsigned int) e->trigger_time; @@ -41,8 +41,8 @@ static unsigned int DedupeHashFunc(void *x) static int CompareDedupes(void *x, void *y) { - DedupeEntry *a = (DedupeEntry *) x; - DedupeEntry *b = (DedupeEntry *) y; + DedupeEntry const *a = (DedupeEntry const *) x; + DedupeEntry const *b = (DedupeEntry const *) y; if (a->trigger_date != b->trigger_date) return a->trigger_date - b->trigger_date; if (a->trigger_time != b->trigger_time) return a->trigger_time - b->trigger_time; return strcmp(a->body, b->body); @@ -122,7 +122,7 @@ InsertDedupeEntry(int trigger_date, int trigger_time, char const *body) int ShouldDedupe(int trigger_date, int trigger_time, char const *body) { - DedupeEntry *e = FindDedupeEntry(trigger_date, trigger_time, body); + DedupeEntry const *e = FindDedupeEntry(trigger_date, trigger_time, body); if (e) { return 1; diff --git a/src/files.c b/src/files.c index 8cba8182..116f6fe3 100644 --- a/src/files.c +++ b/src/files.c @@ -116,14 +116,14 @@ static int IncludeCmd(char const *); static unsigned int FnHashFunc(void *x) { - FilenameHashEntry *e = (FilenameHashEntry *) x; + FilenameHashEntry const *e = (FilenameHashEntry const *) x; return HashVal_preservecase(e->fname); } static int FnCompareFunc(void *a, void *b) { - FilenameHashEntry *e1 = (FilenameHashEntry *) a; - FilenameHashEntry *e2 = (FilenameHashEntry *) b; + FilenameHashEntry const *e1 = (FilenameHashEntry const *) a; + FilenameHashEntry const *e2 = (FilenameHashEntry const *) b; return strcmp(e1->fname, e2->fname); } @@ -1151,7 +1151,7 @@ int IncludeFile(char const *fname) int GetAccessDate(char const *file) { struct stat statbuf; - struct tm *t1; + struct tm const *t1; if (stat(file, &statbuf)) return -1; t1 = localtime(&(statbuf.st_atime)); diff --git a/src/hashtab.c b/src/hashtab.c index e823234a..4ec8bfbe 100644 --- a/src/hashtab.c +++ b/src/hashtab.c @@ -141,7 +141,7 @@ hash_table_free(hash_table *t) * \return The number of items in the hash table */ size_t -hash_table_num_entries(hash_table *t) +hash_table_num_entries(hash_table const *t) { return t->num_entries; } @@ -154,7 +154,7 @@ hash_table_num_entries(hash_table *t) * \return The number of buckets in the hash table */ size_t -hash_table_num_buckets(hash_table *t) +hash_table_num_buckets(hash_table const *t) { if (t->bucket_choice_index >= NUM_BUCKET_CHOICES) { return 0; diff --git a/src/hashtab.h b/src/hashtab.h index 52825a10..8e594a74 100644 --- a/src/hashtab.h +++ b/src/hashtab.h @@ -59,8 +59,8 @@ int hash_table_init(hash_table *t, unsigned int (*hashfunc)(void *x), int (*compare)(void *a, void *b)); void hash_table_free(hash_table *t); -size_t hash_table_num_entries(hash_table *t); -size_t hash_table_num_buckets(hash_table *t); +size_t hash_table_num_entries(hash_table const *t); +size_t hash_table_num_buckets(hash_table const *t); size_t hash_table_chain_len(hash_table *t, size_t i); int hash_table_insert(hash_table *t, void *item); void *hash_table_find(hash_table *t, void *candidate); diff --git a/src/init.c b/src/init.c index 36be8877..4b37c1ac 100644 --- a/src/init.c +++ b/src/init.c @@ -1063,7 +1063,7 @@ static void InitializeVar(char const *str) static void AddTrustedUser(char const *username) { - struct passwd *pwent; + struct passwd const *pwent; if (NumTrustedUsers >= MAX_TRUSTED_USERS) { fprintf(ErrFp, "Too many trusted users (%d max)\n", MAX_TRUSTED_USERS); diff --git a/src/moon.c b/src/moon.c index 46db4c3b..95e2981c 100644 --- a/src/moon.c +++ b/src/moon.c @@ -636,7 +636,7 @@ static time_t time_t_from_dse(int dse) static int datetime_from_time_t(time_t t) { - struct tm *local; + struct tm const *local; int ans; /* Round to nearest minute */ diff --git a/src/token.c b/src/token.c index a35d7b19..1d285b2e 100644 --- a/src/token.c +++ b/src/token.c @@ -443,7 +443,7 @@ static int TokStrCmp(Token const *t, char const *s) } static void -print_token(Token *tok) +print_token(Token const *tok) { if (tok->MinLen < (int) strlen(tok->name)) { printf("%.*s\n", tok->MinLen, tok->name); diff --git a/src/trans.c b/src/trans.c index 2d2e4f0e..2e6edaf3 100644 --- a/src/trans.c +++ b/src/trans.c @@ -274,15 +274,15 @@ DumpTranslationTable(FILE *fp, int json) static unsigned int HashXlateItem(void *x) { - XlateItem *item = (XlateItem *) x; + XlateItem const *item = (XlateItem const *) x; return HashVal_preservecase(item->orig); } static int CompareXlateItems(void *a, void *b) { - XlateItem *i = (XlateItem *) a; - XlateItem *j = (XlateItem *) b; + XlateItem const *i = (XlateItem const *) a; + XlateItem const *j = (XlateItem const *) b; return strcmp(i->orig, j->orig); } @@ -339,7 +339,7 @@ InsertTranslation(char const *orig, char const *translated) char const * GetTranslatedString(char const *orig) { - XlateItem *item = FindTranslation(orig); + XlateItem const *item = FindTranslation(orig); if (!item) return NULL; return item->translated; } diff --git a/src/userfns.c b/src/userfns.c index 6a0105f8..eddf16ef 100644 --- a/src/userfns.c +++ b/src/userfns.c @@ -38,14 +38,14 @@ static void RenameUserFunc(char const *oldname, char const *newname); static unsigned int HashUserFunc(void *x) { - UserFunc *f = (UserFunc *) x; + UserFunc const *f = (UserFunc const *) x; return HashVal_preservecase(f->name); } static int CompareUserFuncs(void *a, void *b) { - UserFunc *f = (UserFunc *) a; - UserFunc *g = (UserFunc *) b; + UserFunc const *f = (UserFunc const *) a; + UserFunc const *g = (UserFunc const *) b; return strcmp(f->name, g->name); } diff --git a/src/utils.c b/src/utils.c index 0c8d9512..64b37f04 100644 --- a/src/utils.c +++ b/src/utils.c @@ -247,7 +247,7 @@ print_callstack_aux(FILE *fp, cs *entry) { int i = 0; char const *in = tr("In"); - cs *prev = NULL; + cs const *prev = NULL; while(entry) { if (prev) { in = tr("Called from"); diff --git a/src/var.c b/src/var.c index 0be4b55b..fa4a047c 100644 --- a/src/var.c +++ b/src/var.c @@ -40,7 +40,7 @@ static int SetSysVarHelper(SysVar *v, Value *value); static unsigned int VarHashFunc(void *x) { - Var *v = (Var *) x; + Var const *v = (Var const *) x; return HashVal_ignorecase(v->name); } @@ -1100,12 +1100,12 @@ static SysVar SysVarArr[] = { #define NUMSYSVARS ( sizeof(SysVarArr) / sizeof(SysVar) ) static void DumpSysVar (char const *name, const SysVar *v); -static int SetTranslatableVariable(SysVar *v, Value *value) +static int SetTranslatableVariable(SysVar const *v, Value const *value) { return InsertTranslation((char const *) v->value, value->v.str); } -static int GetTranslatableVariable(SysVar *v, Value *value) +static int GetTranslatableVariable(SysVar const *v, Value *value) { char const *translated = tr((char const *) v->value); if (translated) { @@ -1256,7 +1256,7 @@ SysVar *FindSysVar(char const *name) void DumpSysVarByName(char const *name) { size_t i; - SysVar *v; + SysVar const *v; if (!name || !*name) { for (i=0; i