[PATCH 9/8] Add more const correctness

Rene Kita <[email protected]>
Newsgroups gmane.mail.mutt.devel
Message-ID <[email protected]>
---
Should I amend this to the previous commits?

 crypt-gpgme.c       | 18 +++++++++---------
 hcache.c            |  6 +++---
 imap/imap.c         |  6 +++---
 imap/imap_private.h |  2 +-
 imap/util.c         |  2 +-
 sidebar.c           |  4 ++--
 6 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/crypt-gpgme.c b/crypt-gpgme.c
index a64123e3..d4fa2c4e 100644
--- a/crypt-gpgme.c
+++ b/crypt-gpgme.c
@@ -396,7 +396,7 @@ static const char *crypt_fpr(crypt_key_t *k)
 /* Returns the fingerprint if available, otherwise
  * returns the long keyid.
  */
-static const char *crypt_fpr_or_lkeyid(crypt_key_t *k)
+static const char *crypt_fpr_or_lkeyid(const crypt_key_t *k)
 {
   const char *s = "????????????????";
 
@@ -3483,8 +3483,8 @@ static void crypt_entry(char *s, size_t l, MUTTMENU * menu, int num)
 /* Compare two addresses and the keyid to be used for sorting. */
 static int _crypt_compare_address(const void *a, const void *b)
 {
-  crypt_key_t **s = (crypt_key_t **) a;
-  crypt_key_t **t = (crypt_key_t **) b;
+  const crypt_key_t * const *s = (const crypt_key_t * const *) a;
+  const crypt_key_t * const *t = (const crypt_key_t * const *) b;
   int r;
 
   if ((r = mutt_strcasecmp((*s)->uid, (*t)->uid)))
@@ -3503,8 +3503,8 @@ static int crypt_compare_address(const void *a, const void *b)
 /* Compare two key IDs and the addresses to be used for sorting. */
 static int _crypt_compare_keyid(const void *a, const void *b)
 {
-  crypt_key_t **s = (crypt_key_t **) a;
-  crypt_key_t **t = (crypt_key_t **) b;
+  const crypt_key_t * const *s = (const crypt_key_t * const *) a;
+  const crypt_key_t * const *t = (const crypt_key_t * const *) b;
   int r;
 
   if ((r = mutt_strcasecmp(crypt_fpr_or_lkeyid(*s), crypt_fpr_or_lkeyid(*t))))
@@ -3522,8 +3522,8 @@ static int crypt_compare_keyid(const void *a, const void *b)
 /* Compare 2 creation dates and the addresses.  For sorting. */
 static int _crypt_compare_date(const void *a, const void *b)
 {
-  crypt_key_t **s = (crypt_key_t **) a;
-  crypt_key_t **t = (crypt_key_t **) b;
+  const crypt_key_t * const *s = (const crypt_key_t * const *) a;
+  const crypt_key_t * const *t = (const crypt_key_t * const *) b;
   unsigned long ts = 0, tt = 0;
 
   if ((*s)->kobj->subkeys && ((*s)->kobj->subkeys->timestamp > 0))
@@ -3549,8 +3549,8 @@ static int crypt_compare_date(const void *a, const void *b)
    addresses and the key IDs.  For sorting. */
 static int _crypt_compare_trust(const void *a, const void *b)
 {
-  crypt_key_t **s = (crypt_key_t **) a;
-  crypt_key_t **t = (crypt_key_t **) b;
+  const crypt_key_t * const *s = (const crypt_key_t * const *) a;
+  const crypt_key_t * const *t = (const crypt_key_t * const *) b;
   unsigned long ts = 0, tt = 0;
   int r;
 
diff --git a/hcache.c b/hcache.c
index e959e998..22f8bdf4 100644
--- a/hcache.c
+++ b/hcache.c
@@ -588,7 +588,7 @@ crc_matches(const char *d, unsigned int crc)
   if (!d)
     return 0;
 
-  restore_int(&mycrc, (unsigned char *) d, &off);
+  restore_int(&mycrc, (const unsigned char *) d, &off);
 
   return (crc == mycrc);
 }
@@ -1189,12 +1189,12 @@ hcache_open_gdbm(struct header_cache *h, const char *path)
   if (pagesize <= 0)
     pagesize = 16384;
 
-  h->db = gdbm_open((char *) path, pagesize, GDBM_WRCREAT, 00600, NULL);
+  h->db = gdbm_open(path, pagesize, GDBM_WRCREAT, 00600, NULL);
   if (h->db)
     return 0;
 
   /* if rw failed try ro */
-  h->db = gdbm_open((char *) path, pagesize, GDBM_READER, 00600, NULL);
+  h->db = gdbm_open(path, pagesize, GDBM_READER, 00600, NULL);
   if (h->db)
     return 0;
 
diff --git a/imap/imap.c b/imap/imap.c
index 4fe1beed..0ce804e5 100644
--- a/imap/imap.c
+++ b/imap/imap.c
@@ -1160,8 +1160,8 @@ int imap_has_flag(LIST *flag_list, const char *flag)
 
 static int compare_uid(const void *a, const void *b)
 {
-  HEADER **pa = (HEADER **) a;
-  HEADER **pb = (HEADER **) b;
+  const HEADER * const *pa = (const HEADER * const *) a;
+  const HEADER * const *pb = (const HEADER * const *) b;
 
   return mutt_numeric_cmp(HEADER_DATA(*pa)->uid, HEADER_DATA(*pb)->uid);
 }
@@ -2089,7 +2089,7 @@ IMAP_STATUS *imap_mboxcache_get(IMAP_DATA *idata, const char *mbox, int create)
   if (create)
   {
     memset(&scache, 0, sizeof(scache));
-    scache.name = (char*)mbox;
+    scache.name = mbox;
     idata->mboxcache = mutt_add_list_n(idata->mboxcache, &scache,
                                        sizeof(scache));
     status = imap_mboxcache_get(idata, mbox, 0);
diff --git a/imap/imap_private.h b/imap/imap_private.h
index 6e6cd9ac..f417e327 100644
--- a/imap/imap_private.h
+++ b/imap/imap_private.h
@@ -137,7 +137,7 @@ typedef struct
 
 typedef struct
 {
-  char *name;
+  const char *name;
 
   unsigned int messages;
   unsigned int recent;
diff --git a/imap/util.c b/imap/util.c
index bff1e1c6..30dacc5a 100644
--- a/imap/util.c
+++ b/imap/util.c
@@ -884,7 +884,7 @@ void imap_unmunge_mbox_name(IMAP_DATA *idata, char *s)
 int imap_wordcasecmp(const char *a, const char *b)
 {
   char tmp[SHORT_STRING];
-  char *s = (char *)b;
+  const char *s = b;
   int i;
 
   tmp[SHORT_STRING-1] = 0;
diff --git a/sidebar.c b/sidebar.c
index 1db5e05a..5a6b143f 100644
--- a/sidebar.c
+++ b/sidebar.c
@@ -249,8 +249,8 @@ static void make_sidebar_entry(char *buf, unsigned int buflen, int width, const
  */
 static int cb_qsort_sbe(const void *a, const void *b)
 {
-  const SBENTRY *sbe1 = *(const SBENTRY **) a;
-  const SBENTRY *sbe2 = *(const SBENTRY **) b;
+  const SBENTRY *sbe1 = *(const SBENTRY * const *) a;
+  const SBENTRY *sbe2 = *(const SBENTRY * const *) b;
   BUFFY *b1 = sbe1->buffy;
   BUFFY *b2 = sbe2->buffy;
 
-- 
2.51.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.