]> granicus.if.org Git - neomutt/commitdiff
Do not cast const qualifier from sort callbacks
authorFederico Kircheis <federico.kircheis@gmail.com>
Wed, 10 Jul 2019 18:30:30 +0000 (20:30 +0200)
committerRichard Russon <rich@flatcap.org>
Sat, 13 Jul 2019 23:10:35 +0000 (00:10 +0100)
If `const void*` points to an instance of type `T`, then it should be
casted to a `const T*` instance.

If `const void*` is a pointer to an instance of type `T`, then the pointer
is `const T*`.

The instance could be `const`, or could be not, but to be on the safe
side, it's casted to `T const *const *`.
In the case of pointer-to-pointer, `const` is on the right to ease
readability; from right to leaft it reads:
A pointer to a const pointer to a const T.

addrbook.c
browser.c
config/dump.c
mutt_thread.c
ncrypt/pgpkey.c
sidebar.c
sort.c
test/config/common.c

index f4e61e9436eb4ea090ed8e51b56caf7154a60332..c8546fac0477546f6b8241a6188b3521ecd3d7d8 100644 (file)
@@ -140,8 +140,8 @@ static int alias_tag(struct Menu *menu, int sel, int act)
  */
 static int alias_sort_alias(const void *a, const void *b)
 {
-  struct Alias *pa = *(struct Alias **) a;
-  struct Alias *pb = *(struct Alias **) b;
+  const struct Alias *pa = *(struct Alias const *const *) a;
+  const struct Alias *pb = *(struct Alias const *const *) b;
   int r = mutt_str_strcasecmp(pa->name, pb->name);
 
   return RSORT(r);
@@ -157,8 +157,8 @@ static int alias_sort_alias(const void *a, const void *b)
  */
 static int alias_sort_address(const void *a, const void *b)
 {
-  struct AddressList *pal = &(*(struct Alias **) a)->addr;
-  struct AddressList *pbl = &(*(struct Alias **) b)->addr;
+  const struct AddressList *pal = &(*(struct Alias const *const *) a)->addr;
+  const struct AddressList *pbl = &(*(struct Alias const *const *) b)->addr;
   int r;
 
   if (pal == pbl)
@@ -169,8 +169,8 @@ static int alias_sort_address(const void *a, const void *b)
     r = 1;
   else
   {
-    struct Address *pa = TAILQ_FIRST(pal);
-    struct Address *pb = TAILQ_FIRST(pbl);
+    const struct Address *pa = TAILQ_FIRST(pal);
+    const struct Address *pb = TAILQ_FIRST(pbl);
     if (pa->personal)
     {
       if (pb->personal)
index 99917b0dee93e9303e222529bcc526251f96b7e1..4846c736d7cafe7308ec7bd3d5f835de047c6e39 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -145,8 +145,8 @@ static void destroy_state(struct BrowserState *state)
  */
 static int browser_compare_subject(const void *a, const void *b)
 {
-  struct FolderFile *pa = (struct FolderFile *) a;
-  struct FolderFile *pb = (struct FolderFile *) b;
+  const struct FolderFile *pa = (const struct FolderFile *) a;
+  const struct FolderFile *pb = (const struct FolderFile *) b;
 
   /* inbox should be sorted ahead of its siblings */
   int r = mutt_inbox_cmp(pa->name, pb->name);
@@ -165,8 +165,8 @@ static int browser_compare_subject(const void *a, const void *b)
  */
 static int browser_compare_desc(const void *a, const void *b)
 {
-  struct FolderFile *pa = (struct FolderFile *) a;
-  struct FolderFile *pb = (struct FolderFile *) b;
+  const struct FolderFile *pa = (const struct FolderFile *) a;
+  const struct FolderFile *pb = (const struct FolderFile *) b;
 
   int r = mutt_str_strcoll(pa->desc, pb->desc);
 
@@ -183,8 +183,8 @@ static int browser_compare_desc(const void *a, const void *b)
  */
 static int browser_compare_date(const void *a, const void *b)
 {
-  struct FolderFile *pa = (struct FolderFile *) a;
-  struct FolderFile *pb = (struct FolderFile *) b;
+  const struct FolderFile *pa = (const struct FolderFile *) a;
+  const struct FolderFile *pb = (const struct FolderFile *) b;
 
   int r = pa->mtime - pb->mtime;
 
@@ -201,8 +201,8 @@ static int browser_compare_date(const void *a, const void *b)
  */
 static int browser_compare_size(const void *a, const void *b)
 {
-  struct FolderFile *pa = (struct FolderFile *) a;
-  struct FolderFile *pb = (struct FolderFile *) b;
+  const struct FolderFile *pa = (const struct FolderFile *) a;
+  const struct FolderFile *pb = (const struct FolderFile *) b;
 
   int r = pa->size - pb->size;
 
@@ -219,8 +219,8 @@ static int browser_compare_size(const void *a, const void *b)
  */
 static int browser_compare_count(const void *a, const void *b)
 {
-  struct FolderFile *pa = (struct FolderFile *) a;
-  struct FolderFile *pb = (struct FolderFile *) b;
+  const struct FolderFile *pa = (const struct FolderFile *) a;
+  const struct FolderFile *pb = (const struct FolderFile *) b;
 
   int r = 0;
   if (pa->has_mailbox && pb->has_mailbox)
@@ -243,8 +243,8 @@ static int browser_compare_count(const void *a, const void *b)
  */
 static int browser_compare_count_new(const void *a, const void *b)
 {
-  struct FolderFile *pa = (struct FolderFile *) a;
-  struct FolderFile *pb = (struct FolderFile *) b;
+  const struct FolderFile *pa = (const struct FolderFile *) a;
+  const struct FolderFile *pb = (const struct FolderFile *) b;
 
   int r = 0;
   if (pa->has_mailbox && pb->has_mailbox)
@@ -271,8 +271,8 @@ static int browser_compare_count_new(const void *a, const void *b)
  */
 static int browser_compare(const void *a, const void *b)
 {
-  struct FolderFile *pa = (struct FolderFile *) a;
-  struct FolderFile *pb = (struct FolderFile *) b;
+  const struct FolderFile *pa = (const struct FolderFile *) a;
+  const struct FolderFile *pb = (const struct FolderFile *) b;
 
   if ((mutt_str_strcoll(pa->desc, "../") == 0) || (mutt_str_strcoll(pa->desc, "..") == 0))
     return -1;
index 9f06d72d2287529658bef6cb21e56f387c03dc3c..a128682e9db5a0e14bd0faf6b593e9636c782941 100644 (file)
@@ -105,8 +105,8 @@ int elem_list_sort(const void *a, const void *b)
   if (!a || !b)
     return 0;
 
-  const struct HashElem *hea = *(struct HashElem **) a;
-  const struct HashElem *heb = *(struct HashElem **) b;
+  const struct HashElem *hea = *(struct HashElem const *const *) a;
+  const struct HashElem *heb = *(struct HashElem const *const *) b;
 
   return mutt_str_strcasecmp(hea->key.strkey, heb->key.strkey);
 }
index c804bda7182c40070417a3c1252a1bf0b4b15a8d..d21f29b70f0253823a2039fc288a732a0118ea82 100644 (file)
@@ -635,8 +635,8 @@ static int compare_threads(const void *a, const void *b)
 
   if (a && b)
   {
-    return (*sort_func)(&(*((struct MuttThread **) a))->sort_key,
-                        &(*((struct MuttThread **) b))->sort_key);
+    return (*sort_func)(&(*((struct MuttThread const *const *) a))->sort_key,
+                        &(*((struct MuttThread const *const *) b))->sort_key);
   }
   /* a hack to let us reset sort_func even though we can't
    * have extra arguments because of qsort */
index 3353f39641eedebe36564a20d31f4d839982e25e..813fca7811988a0d15781751f90badd0130324c5 100644 (file)
@@ -353,8 +353,8 @@ static int compare_key_address(const void *a, const void *b)
 {
   int r;
 
-  struct PgpUid **s = (struct PgpUid **) a;
-  struct PgpUid **t = (struct PgpUid **) b;
+  struct PgpUid const *const *s = (struct PgpUid const *const *) a;
+  struct PgpUid const *const *t = (struct PgpUid const *const *) b;
 
   r = mutt_str_strcasecmp((*s)->addr, (*t)->addr);
   if (r != 0)
@@ -392,8 +392,8 @@ static int compare_keyid(const void *a, const void *b)
 {
   int r;
 
-  struct PgpUid **s = (struct PgpUid **) a;
-  struct PgpUid **t = (struct PgpUid **) b;
+  struct PgpUid const *const *s = (struct PgpUid const *const *) a;
+  struct PgpUid const *const *t = (struct PgpUid const *const *) b;
 
   r = mutt_str_strcasecmp(pgp_fpr_or_lkeyid((*s)->parent), pgp_fpr_or_lkeyid((*t)->parent));
   if (r != 0)
@@ -426,8 +426,8 @@ static int pgp_compare_keyid(const void *a, const void *b)
 static int compare_key_date(const void *a, const void *b)
 {
   int r;
-  struct PgpUid **s = (struct PgpUid **) a;
-  struct PgpUid **t = (struct PgpUid **) b;
+  struct PgpUid const *const *s = (struct PgpUid const *const *) a;
+  struct PgpUid const *const *t = (struct PgpUid const *const *) b;
 
   r = ((*s)->parent->gen_time - (*t)->parent->gen_time);
   if (r != 0)
@@ -464,8 +464,8 @@ static int compare_key_trust(const void *a, const void *b)
 {
   int r;
 
-  struct PgpUid **s = (struct PgpUid **) a;
-  struct PgpUid **t = (struct PgpUid **) b;
+  struct PgpUid const *const *s = (struct PgpUid const *const *) a;
+  struct PgpUid const *const *t = (struct PgpUid const *const *) b;
 
   r = (((*s)->parent->flags & KEYFLAG_RESTRICTIONS) -
        ((*t)->parent->flags & KEYFLAG_RESTRICTIONS));
index 0f5caed83c8ecec6d76ec5c86df66ad61642fc11..042c9636be72d85bc97fa8e1d004a37d13dcefd7 100644 (file)
--- a/sidebar.c
+++ b/sidebar.c
@@ -297,10 +297,10 @@ static void make_sidebar_entry(char *buf, size_t buflen, int width,
  */
 static int cb_qsort_sbe(const void *a, const void *b)
 {
-  const struct SbEntry *sbe1 = *(const struct SbEntry **) a;
-  const struct SbEntry *sbe2 = *(const struct SbEntry **) b;
-  struct Mailbox *m1 = sbe1->mailbox;
-  struct Mailbox *m2 = sbe2->mailbox;
+  const struct SbEntry *sbe1 = *(struct SbEntry const *const *) a;
+  const struct SbEntry *sbe2 = *(struct SbEntry const *const *) b;
+  const struct Mailbox *m1 = sbe1->mailbox;
+  const struct Mailbox *m2 = sbe2->mailbox;
 
   int rc = 0;
 
diff --git a/sort.c b/sort.c
index ebab9247dfe457af5e70f505b6ade4d2bde310c4..74842771014e3d18f7be8623af3f6e165d406af9 100644 (file)
--- a/sort.c
+++ b/sort.c
@@ -78,7 +78,8 @@ int perform_auxsort(int retval, const void *a, const void *b)
   /* If the items still match, use their index positions
    * to maintain a stable sort order */
   if (retval == 0)
-    retval = (*((struct Email **) a))->index - (*((struct Email **) b))->index;
+    retval = (*((struct Email const *const *) a))->index -
+             (*((struct Email const *const *) b))->index;
   return retval;
 }
 
@@ -87,8 +88,8 @@ int perform_auxsort(int retval, const void *a, const void *b)
  */
 static int compare_score(const void *a, const void *b)
 {
-  struct Email **pa = (struct Email **) a;
-  struct Email **pb = (struct Email **) b;
+  struct Email const *const *pa = (struct Email const *const *) a;
+  struct Email const *const *pb = (struct Email const *const *) b;
   int result = (*pb)->score - (*pa)->score; /* note that this is reverse */
   result = perform_auxsort(result, a, b);
   return SORT_CODE(result);
@@ -99,8 +100,8 @@ static int compare_score(const void *a, const void *b)
  */
 static int compare_size(const void *a, const void *b)
 {
-  struct Email **pa = (struct Email **) a;
-  struct Email **pb = (struct Email **) b;
+  struct Email const *const *pa = (struct Email const *const *) a;
+  struct Email const *const *pb = (struct Email const *const *) b;
   int result = (*pa)->content->length - (*pb)->content->length;
   result = perform_auxsort(result, a, b);
   return SORT_CODE(result);
@@ -111,8 +112,8 @@ static int compare_size(const void *a, const void *b)
  */
 static int compare_date_sent(const void *a, const void *b)
 {
-  struct Email **pa = (struct Email **) a;
-  struct Email **pb = (struct Email **) b;
+  struct Email const *const *pa = (struct Email const *const *) a;
+  struct Email const *const *pb = (struct Email const *const *) b;
   int result = (*pa)->date_sent - (*pb)->date_sent;
   result = perform_auxsort(result, a, b);
   return SORT_CODE(result);
@@ -123,8 +124,8 @@ static int compare_date_sent(const void *a, const void *b)
  */
 static int compare_subject(const void *a, const void *b)
 {
-  struct Email **pa = (struct Email **) a;
-  struct Email **pb = (struct Email **) b;
+  struct Email const *const *pa = (struct Email const *const *) a;
+  struct Email const *const *pb = (struct Email const *const *) b;
   int rc;
 
   if (!(*pa)->env->real_subj)
@@ -174,8 +175,8 @@ const char *mutt_get_name(const struct Address *a)
  */
 static int compare_to(const void *a, const void *b)
 {
-  struct Email **ppa = (struct Email **) a;
-  struct Email **ppb = (struct Email **) b;
+  struct Email const *const *ppa = (struct Email const *const *) a;
+  struct Email const *const *ppb = (struct Email const *const *) b;
   char fa[128];
 
   mutt_str_strfcpy(fa, mutt_get_name(TAILQ_FIRST(&(*ppa)->env->to)), sizeof(fa));
@@ -190,8 +191,8 @@ static int compare_to(const void *a, const void *b)
  */
 static int compare_from(const void *a, const void *b)
 {
-  struct Email **ppa = (struct Email **) a;
-  struct Email **ppb = (struct Email **) b;
+  struct Email const *const *ppa = (struct Email const *const *) a;
+  struct Email const *const *ppb = (struct Email const *const *) b;
   char fa[128];
 
   mutt_str_strfcpy(fa, mutt_get_name(TAILQ_FIRST(&(*ppa)->env->from)), sizeof(fa));
@@ -206,8 +207,8 @@ static int compare_from(const void *a, const void *b)
  */
 static int compare_date_received(const void *a, const void *b)
 {
-  struct Email **pa = (struct Email **) a;
-  struct Email **pb = (struct Email **) b;
+  struct Email const *const *pa = (struct Email const *const *) a;
+  struct Email const *const *pb = (struct Email const *const *) b;
   int result = (*pa)->received - (*pb)->received;
   result = perform_auxsort(result, a, b);
   return SORT_CODE(result);
@@ -218,8 +219,8 @@ static int compare_date_received(const void *a, const void *b)
  */
 static int compare_order(const void *a, const void *b)
 {
-  struct Email **ea = (struct Email **) a;
-  struct Email **eb = (struct Email **) b;
+  struct Email const *const *ea = (struct Email const *const *) a;
+  struct Email const *const *eb = (struct Email const *const *) b;
 
   /* no need to auxsort because you will never have equality here */
   return SORT_CODE((*ea)->index - (*eb)->index);
@@ -230,8 +231,8 @@ static int compare_order(const void *a, const void *b)
  */
 static int compare_spam(const void *a, const void *b)
 {
-  struct Email **ppa = (struct Email **) a;
-  struct Email **ppb = (struct Email **) b;
+  struct Email const *const *ppa = (struct Email const *const *) a;
+  struct Email const *const *ppb = (struct Email const *const *) b;
   char *aptr = NULL, *bptr = NULL;
   int ahas, bhas;
   int result = 0;
@@ -286,8 +287,8 @@ static int compare_spam(const void *a, const void *b)
  */
 static int compare_label(const void *a, const void *b)
 {
-  struct Email **ppa = (struct Email **) a;
-  struct Email **ppb = (struct Email **) b;
+  struct Email const *const *ppa = (struct Email const *const *) a;
+  struct Email const *const *ppb = (struct Email const *const *) b;
   int ahas, bhas, result = 0;
 
   /* As with compare_spam, not all messages will have the x-label
index 2c7a947062a1b61e934a2eba0963456cc5c9fdcc..c9732e7ed3cd3b3651c033ef768ddc92dd82756e 100644 (file)
@@ -119,8 +119,8 @@ void set_list(const struct ConfigSet *cs)
 
 int sort_list_cb(const void *a, const void *b)
 {
-  const char *stra = *(char **) a;
-  const char *strb = *(char **) b;
+  const char *stra = *(char const *const *) a;
+  const char *strb = *(char const *const *) b;
   return strcmp(stra, strb);
 }