[neomutt-devel] [PATCH 1/2] remove dead code in compose_format_str()

toogley toogley at nixnet.email
Fri Mar 19 12:19:03 CET 2021


compose_format_str() contains this code:

  bool optional = (flags & MUTT_FORMAT_OPTIONAL);
[...]
  if (optional)
  {
    mutt_expando_format(buf, buflen, col, cols, if_str, compose_format_str, data, flags);
  }
  else if (flags & MUTT_FORMAT_OPTIONAL)
  {
    mutt_expando_format(buf, buflen, col, cols, else_str, compose_format_str, data, flags);
  }

The second if branch will never be taken, but only in this specific
case. So we have similar patterns in for instance browser.c[1], but
there, the optional variable is reset in some cases[2], so the second if
branch will sometimes be taken since optional might be false but (flags
& MUTT_FORMAT_OPTIONAL) might be true.

This is the case for all other format_str methods in neomutt currently.
This is also the case in upstream mutt[3].

[1]: https://github.com/neomutt/neomutt/blob/master/browser.c#L595-L599
[2]: https://github.com/neomutt/neomutt/blob/master/browser.c#L529
[3]: https://gitlab.com/muttmua/mutt/-/blob/master/compose.c#L961
---
 compose/compose.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/compose/compose.c b/compose/compose.c
index 62ec4d1f7..5ba53102e 100644
--- a/compose/compose.c
+++ b/compose/compose.c
@@ -1293,10 +1293,6 @@ static const char *compose_format_str(char *buf, size_t buflen, size_t col, int
   {
     mutt_expando_format(buf, buflen, col, cols, if_str, compose_format_str, data, flags);
   }
-  else if (flags & MUTT_FORMAT_OPTIONAL)
-  {
-    mutt_expando_format(buf, buflen, col, cols, else_str, compose_format_str, data, flags);
-  }
 
   return src;
 }
-- 
2.30.2



More information about the neomutt-devel mailing list