[neomutt-devel] NeoMutt 2023-11-03

наб nabijaczleweli at nabijaczleweli.xyz
Fri Nov 3 20:08:03 CET 2023


On Fri, Nov 03, 2023 at 06:50:18PM +0100, наб wrote:
> On Fri, Nov 03, 2023 at 10:33:05AM +0000, Richard Russon wrote:
> > Behind the scenes, I added a lot of tests for the colour code.
> > This revealed a handful of bugs that needed fixing.
And another tranche of invalid format strings.

In this case I've decided to preserve the actual gettexted
format-strings to match the argument to the string, but in some
cases the format-strings themselves ought to be fixed, with matching
translation-string fixes. The most egregious of this is the off_t
formatted as a long, which should've been a %lld and (long long)
cast, of course.

Best,
-- >8 --
Subject: [PATCH] ILP32 -Wformat; out-of-bounds index

---
 config/bool.c        | 2 +-
 config/enum.c        | 2 +-
 config/number.c      | 2 +-
 config/quad.c        | 2 +-
 config/sort.c        | 2 +-
 conn/connaccount.c   | 2 +-
 conn/zstrm.c         | 4 ++--
 envelope/window.c    | 2 +-
 imap/command.c       | 8 ++++----
 mutt_logging.c       | 2 +-
 nntp/nntp.c          | 2 +-
 notmuch/notmuch.c    | 8 ++++----
 pager/display.c      | 6 +++---
 rfc3676.c            | 6 +++---
 send/smtp.c          | 4 ++--
 test/config/common.c | 6 +++---
 test/config/slist.c  | 2 +-
 17 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/config/bool.c b/config/bool.c
index 517f3dc57..2b64d40cf 100644
--- a/config/bool.c
+++ b/config/bool.c
@@ -127,7 +127,7 @@ static int bool_native_set(const struct ConfigSet *cs, void *var,
 {
   if ((value < 0) || (value > 1))
   {
-    buf_printf(err, _("Invalid boolean value: %ld"), value);
+    buf_printf(err, _("Invalid boolean value: %ld"), (long) value);
     return CSR_ERR_INVALID | CSR_INV_TYPE;
   }
 
diff --git a/config/enum.c b/config/enum.c
index 700428890..f57517653 100644
--- a/config/enum.c
+++ b/config/enum.c
@@ -129,7 +129,7 @@ static int enum_native_set(const struct ConfigSet *cs, void *var,
   const char *name = mutt_map_get_name(value, ed->lookup);
   if (!name)
   {
-    buf_printf(err, _("Invalid enum value: %ld"), value);
+    buf_printf(err, _("Invalid enum value: %ld"), (long) value);
     return CSR_ERR_INVALID | CSR_INV_TYPE;
   }
 
diff --git a/config/number.c b/config/number.c
index a000ca4c0..7da704210 100644
--- a/config/number.c
+++ b/config/number.c
@@ -118,7 +118,7 @@ static int number_native_set(const struct ConfigSet *cs, void *var,
 {
   if ((value < SHRT_MIN) || (value > SHRT_MAX))
   {
-    buf_printf(err, _("Invalid number: %ld"), value);
+    buf_printf(err, _("Invalid number: %ld"), (long) value);
     return CSR_ERR_INVALID | CSR_INV_TYPE;
   }
 
diff --git a/config/quad.c b/config/quad.c
index 24de6b3ba..4c742c73d 100644
--- a/config/quad.c
+++ b/config/quad.c
@@ -129,7 +129,7 @@ static int quad_native_set(const struct ConfigSet *cs, void *var,
 {
   if ((value < 0) || (value >= (mutt_array_size(QuadValues) - 1)))
   {
-    buf_printf(err, _("Invalid quad value: %ld"), value);
+    buf_printf(err, _("Invalid quad value: %ld"), (long) value);
     return CSR_ERR_INVALID | CSR_INV_TYPE;
   }
 
diff --git a/config/sort.c b/config/sort.c
index 507b0f92b..e6581f464 100644
--- a/config/sort.c
+++ b/config/sort.c
@@ -158,7 +158,7 @@ static int sort_native_set(const struct ConfigSet *cs, void *var,
 
   if (!str)
   {
-    buf_printf(err, _("Invalid sort type: %ld"), value);
+    buf_printf(err, _("Invalid sort type: %ld"), (long) value);
     return CSR_ERR_INVALID | CSR_INV_TYPE;
   }
 
diff --git a/conn/connaccount.c b/conn/connaccount.c
index 9fb15f45f..a30df981b 100644
--- a/conn/connaccount.c
+++ b/conn/connaccount.c
@@ -237,7 +237,7 @@ char *mutt_account_getoauthbearer(struct ConnAccount *cac, bool xoauth2)
 
   if ((!xoauth2 && (token_size > 512)) || (xoauth2 && (token_size > 4096)))
   {
-    mutt_error(_("OAUTH token is too big: %ld"), token_size);
+    mutt_error(_("OAUTH token is too big: %ld"), (long) token_size);
     FREE(&token);
     return NULL;
   }
diff --git a/conn/zstrm.c b/conn/zstrm.c
index c754222ab..78c693551 100644
--- a/conn/zstrm.c
+++ b/conn/zstrm.c
@@ -157,7 +157,7 @@ retry:
   zctx->read.z.next_out = (Bytef *) buf;
 
   zrc = inflate(&zctx->read.z, Z_SYNC_FLUSH);
-  mutt_debug(LL_DEBUG5, "rc=%d, consumed %u/%u bytes, produced %lu/%lu bytes\n",
+  mutt_debug(LL_DEBUG5, "rc=%d, consumed %u/%u bytes, produced %zu/%zu bytes\n",
              zrc, zctx->read.pos - zctx->read.z.avail_in, zctx->read.pos,
              len - zctx->read.z.avail_out, len);
 
@@ -243,7 +243,7 @@ static int zstrm_write(struct Connection *conn, const char *buf, size_t count)
       /* push out produced data to the underlying stream */
       zctx->write.pos = zctx->write.len - zctx->write.z.avail_out;
       char *wbufp = zctx->write.buf;
-      mutt_debug(LL_DEBUG5, "deflate consumed %lu/%lu bytes\n",
+      mutt_debug(LL_DEBUG5, "deflate consumed %zu/%zu bytes\n",
                  count - zctx->write.z.avail_in, count);
       while (zctx->write.pos > 0)
       {
diff --git a/envelope/window.c b/envelope/window.c
index c2b4797d9..ecc1e4007 100644
--- a/envelope/window.c
+++ b/envelope/window.c
@@ -638,7 +638,7 @@ static int draw_envelope_addr(int field, struct AddressList *al,
       width_left -= addr_len;
     }
     mutt_debug(LL_DEBUG3, "%d addresses remaining\n", count);
-    mutt_debug(LL_DEBUG3, "%ld lines remaining\n", max_lines - lines_used);
+    mutt_debug(LL_DEBUG3, "%zd lines remaining\n", max_lines - lines_used);
   }
   mutt_list_free(&list);
   buf_pool_release(&buf);
diff --git a/imap/command.c b/imap/command.c
index 34ff0a16e..a498856be 100644
--- a/imap/command.c
+++ b/imap/command.c
@@ -557,7 +557,7 @@ static void cmd_parse_capability(struct ImapAccountData *adata, char *s)
       if (len != 0 && ((s[len] == '\0') || isspace(s[len])))
       {
         adata->capabilities |= (1 << i);
-        mutt_debug(LL_DEBUG3, " Found capability \"%s\": %lu\n", Capabilities[i], i);
+        mutt_debug(LL_DEBUG3, " Found capability \"%s\": %zu\n", Capabilities[i], i);
         break;
       }
     }
@@ -1151,7 +1151,7 @@ int imap_cmd_step(struct ImapAccountData *adata)
     {
       mutt_mem_realloc(&adata->buf, adata->blen + IMAP_CMD_BUFSIZE);
       adata->blen = adata->blen + IMAP_CMD_BUFSIZE;
-      mutt_debug(LL_DEBUG3, "grew buffer to %lu bytes\n", adata->blen);
+      mutt_debug(LL_DEBUG3, "grew buffer to %zu bytes\n", adata->blen);
     }
 
     /* back up over '\0' */
@@ -1177,7 +1177,7 @@ int imap_cmd_step(struct ImapAccountData *adata)
   {
     mutt_mem_realloc(&adata->buf, IMAP_CMD_BUFSIZE);
     adata->blen = IMAP_CMD_BUFSIZE;
-    mutt_debug(LL_DEBUG3, "shrank buffer to %lu bytes\n", adata->blen);
+    mutt_debug(LL_DEBUG3, "shrank buffer to %zu bytes\n", adata->blen);
   }
 
   adata->lastread = mutt_date_now();
@@ -1410,7 +1410,7 @@ void imap_cmd_finish(struct ImapAccountData *adata)
         if (!(mdata->reopen & IMAP_EXPUNGE_PENDING))
           mdata->check_status |= IMAP_NEWMAIL_PENDING;
 
-        mutt_debug(LL_DEBUG2, "Fetching new mails from %ld to %u\n",
+        mutt_debug(LL_DEBUG2, "Fetching new mails from %zd to %u\n",
                    max_msn + 1, mdata->new_mail_count);
         imap_read_headers(adata->mailbox, max_msn + 1, mdata->new_mail_count, false);
       }
diff --git a/mutt_logging.c b/mutt_logging.c
index 952b02577..c0802da0b 100644
--- a/mutt_logging.c
+++ b/mutt_logging.c
@@ -271,7 +271,7 @@ int level_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef,
 {
   if ((value < 0) || (value >= LL_MAX))
   {
-    buf_printf(err, _("Invalid value for option %s: %ld"), cdef->name, value);
+    buf_printf(err, _("Invalid value for option %s: %ld"), cdef->name, (long) value);
     return CSR_ERR_INVALID;
   }
 
diff --git a/nntp/nntp.c b/nntp/nntp.c
index d809efe0a..8cfcf4cb7 100644
--- a/nntp/nntp.c
+++ b/nntp/nntp.c
@@ -1683,7 +1683,7 @@ static int nntp_date(struct NntpAccountData *adata, time_t *now)
       *now = timegm(&tm);
       if (*now >= 0)
       {
-        mutt_debug(LL_DEBUG1, "server time is %lu\n", *now);
+        mutt_debug(LL_DEBUG1, "server time is %llu\n", (unsigned long long) *now);
         return 0;
       }
     }
diff --git a/notmuch/notmuch.c b/notmuch/notmuch.c
index 93d969ed8..717f7298c 100644
--- a/notmuch/notmuch.c
+++ b/notmuch/notmuch.c
@@ -2090,13 +2090,13 @@ static enum MxStatus nm_mbox_check(struct Mailbox *m)
 
   if (mdata->mtime.tv_sec >= mtime)
   {
-    mutt_debug(LL_DEBUG2, "nm: check unnecessary (db=%lu mailbox=%lu)\n", mtime,
-               mdata->mtime.tv_sec);
+    mutt_debug(LL_DEBUG2, "nm: check unnecessary (db=%llu mailbox=%llu)\n",
+               (unsigned long long) mtime, (unsigned long long) mdata->mtime.tv_sec);
     return MX_STATUS_OK;
   }
 
-  mutt_debug(LL_DEBUG1, "nm: checking (db=%lu mailbox=%lu)\n", mtime,
-             mdata->mtime.tv_sec);
+  mutt_debug(LL_DEBUG1, "nm: checking (db=%llu mailbox=%llu)\n",
+             (unsigned long long) mtime, (unsigned long long) mdata->mtime.tv_sec);
 
   notmuch_query_t *q = get_query(m, false);
   if (!q)
diff --git a/pager/display.c b/pager/display.c
index 2f21062aa..0a13a614f 100644
--- a/pager/display.c
+++ b/pager/display.c
@@ -860,7 +860,7 @@ static int format_line(struct MuttWindow *win, struct Line **lines, int line_num
     {
       if (k == ICONV_ILLEGAL_SEQ)
         memset(&mbstate, 0, sizeof(mbstate));
-      mutt_debug(LL_DEBUG1, "mbrtowc returned %lu; errno = %d\n", k, errno);
+      mutt_debug(LL_DEBUG1, "mbrtowc returned %zu; errno = %d\n", k, errno);
       if ((col + 4) > wrap_cols)
         break;
       col += 4;
@@ -970,7 +970,7 @@ static int format_line(struct MuttWindow *win, struct Line **lines, int line_num
         break;
       col += 2;
       if (ansi)
-        mutt_window_printf(win, "^%c", ('@' + wc) & 0x7f);
+        mutt_window_printf(win, "^%c", (char) (('@' + wc) & 0x7f));
     }
     else if (wc < 0x100)
     {
@@ -978,7 +978,7 @@ static int format_line(struct MuttWindow *win, struct Line **lines, int line_num
         break;
       col += 4;
       if (ansi)
-        mutt_window_printf(win, "\\%03o", wc);
+        mutt_window_printf(win, "\\%03lo", (long) wc);
     }
     else
     {
diff --git a/rfc3676.c b/rfc3676.c
index 679a92b7d..52a909557 100644
--- a/rfc3676.c
+++ b/rfc3676.c
@@ -241,12 +241,12 @@ static void print_flowed_line(char *line, struct State *state, int ql,
   width = quote_width(state, ql);
   last = line[mutt_str_len(line) - 1];
 
-  mutt_debug(LL_DEBUG5, "f=f: line [%s], width = %ld, spaces = %lu\n", line,
+  mutt_debug(LL_DEBUG5, "f=f: line [%s], width = %ld, spaces = %zu\n", line,
              (long) width, fst->spaces);
 
   for (words = 0; (p = mutt_str_sep(&line, " "));)
   {
-    mutt_debug(LL_DEBUG5, "f=f: word [%s], width: %lu, remaining = [%s]\n", p,
+    mutt_debug(LL_DEBUG5, "f=f: word [%s], width: %zu, remaining = [%s]\n", p,
                fst->width, line);
 
     /* remember number of spaces */
@@ -268,7 +268,7 @@ static void print_flowed_line(char *line, struct State *state, int ql,
     if (!(!fst->spaces && fst->delsp && (last != ' ')) && (w < width) &&
         (w + fst->width + fst->spaces > width))
     {
-      mutt_debug(LL_DEBUG3, "f=f: break line at %lu, %lu spaces left\n",
+      mutt_debug(LL_DEBUG3, "f=f: break line at %zu, %zu spaces left\n",
                  fst->width, fst->spaces);
       /* only honor trailing spaces for format=flowed replies */
       const bool c_text_flowed = cs_subset_bool(NeoMutt->sub, "text_flowed");
diff --git a/send/smtp.c b/send/smtp.c
index 00c8fbe3a..37caad4b3 100644
--- a/send/smtp.c
+++ b/send/smtp.c
@@ -488,13 +488,13 @@ static int smtp_get_auth_response(struct Connection *conn, struct Buffer *input_
     if (*smtp_rc != SMTP_READY)
       break;
 
-    const char *smtp_response = buf_string(input_buf) + 3;
+    const char *smtp_response = input_buf->data + 3;
     if (*smtp_response)
     {
       smtp_response++;
       buf_addstr(response_buf, smtp_response);
     }
-  } while (buf_string(input_buf)[3] == '-');
+  } while (input_buf->data[3] == '-');
 
   return 0;
 }
diff --git a/test/config/common.c b/test/config/common.c
index 14b196a9d..99c7606fc 100644
--- a/test/config/common.c
+++ b/test/config/common.c
@@ -45,7 +45,7 @@ int validator_fail(const struct ConfigSet *cs, const struct ConfigDef *cdef,
   if (value > 1000000)
     buf_printf(result, "%s: %s, (ptr)", __func__, cdef->name);
   else
-    buf_printf(result, "%s: %s, %ld", __func__, cdef->name, value);
+    buf_printf(result, "%s: %s, %zd", __func__, cdef->name, value);
   return CSR_ERR_INVALID;
 }
 
@@ -55,7 +55,7 @@ int validator_warn(const struct ConfigSet *cs, const struct ConfigDef *cdef,
   if (value > 1000000)
     buf_printf(result, "%s: %s, (ptr)", __func__, cdef->name);
   else
-    buf_printf(result, "%s: %s, %ld", __func__, cdef->name, value);
+    buf_printf(result, "%s: %s, %zd", __func__, cdef->name, value);
   return CSR_SUCCESS | CSR_SUC_WARNING;
 }
 
@@ -65,7 +65,7 @@ int validator_succeed(const struct ConfigSet *cs, const struct ConfigDef *cdef,
   if (value > 1000000)
     buf_printf(result, "%s: %s, (ptr)", __func__, cdef->name);
   else
-    buf_printf(result, "%s: %s, %ld", __func__, cdef->name, value);
+    buf_printf(result, "%s: %s, %zd", __func__, cdef->name, value);
   return CSR_SUCCESS;
 }
 
diff --git a/test/config/slist.c b/test/config/slist.c
index 18f1a50be..7424dfd2a 100644
--- a/test/config/slist.c
+++ b/test/config/slist.c
@@ -120,7 +120,7 @@ static void slist_dump(const struct Slist *list, struct Buffer *buf)
   if (!list || !buf)
     return;
 
-  buf_printf(buf, "[%ld] ", list->count);
+  buf_printf(buf, "[%zu] ", list->count);
 
   struct ListNode *np = NULL;
   STAILQ_FOREACH(np, &list->head, entries)
-- 
2.39.2
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mailman.neomutt.org/pipermail/neomutt-devel-neomutt.org/attachments/20231103/e6514c92/attachment.sig>


More information about the neomutt-devel mailing list