diff mbox series

Fix chkmail loop break condition

Message ID 20211002203732.6175-1-june@causal.agency (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show
Series Fix chkmail loop break condition | expand

Commit Message

june Oct. 2, 2021, 8:37 p.m. UTC
padvance_magic() returns -1 when there are no more paths left, not
zero.
---
 src/mail.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

june Oct. 2, 2021, 9:22 p.m. UTC | #1
For some more context which you may want to add to the commit
message: I noticed dash would always print “you have mail” three
times, and this fixes that. On further investigation, this loop was
taking the last path in MAILPATH (or the only string in MAIL) and
continuing to chop off the last character, so for MAIL=/var/mail/june,
it would stat:

/var/mail/june
/var/mail/jun
/var/mail/ju
/var/mail/j
/var/mail/
/var/mail
/var/mai
/var/ma
/var/m
/var/

And then stop because MAXMBOXES is 10. The three “you have mail”
messages were from /var/mail/june, /var/mail/ and /var/mail.
Herbert Xu April 5, 2024, 9:18 a.m. UTC | #2
On Sat, Oct 02, 2021 at 04:37:32PM -0400, C. McEnroe wrote:
> padvance_magic() returns -1 when there are no more paths left, not
> zero.
> ---
>  src/mail.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Patch applied with a change to check len < 0 instead.  Thanks.
diff mbox series

Patch

diff --git a/src/mail.c b/src/mail.c
index e6baaa1b..ec5bd103 100644
--- a/src/mail.c
+++ b/src/mail.c
@@ -80,7 +80,7 @@  chkmail(void)
 		int len;
 
 		len = padvance_magic(&mpath, nullstr, 2);
-		if (!len)
+		if (len == -1)
 			break;
 		p = stackblock();
 		if (*p == '\0')