On Sep 15, 2004, at 12:34 AM, Mark Crispin wrote:
On Tue, 14 Sep 2004, Brian Redman wrote:
What's the recommended way to guard against trying to access a message via msgno that's greater than nmsgs.
Keep track of all mm_exists() and mm_expunged() events. That will guarantee that at all times you know the number of messages in the mailbox. Never send msgno 0 or a number greater than the number of messages.
I currently check myStream->nmsgs but occasionally when I mail_fetchenvelope(myStream, msgno) I get the fatal error anyway.
You must be doing something wrong; because if you did that you would not have the problem. Between the time you checked myStream->nmsgs and called mail_fetchenvelope() you must have gotten a mm_expunged() event. mm_expunged() events happen only at well-defined points.
Are you sure that you aren't doing something like:
if (msgno <= myStream->nmsgs) {
. . .
mail_ping (myStream);
. . .
env = mail_fetchenvelope (myStream,msgno);
the point being that you called some other mail_xxxxxx() function between your test and calling mail_fetchenvelope().
Thanks Mark, If this code fragment *should* be sufficient then I'll look around for another cause such as faulty thread locking logic in my code or some-such.
if (myStream != nil) {
if (msgno <= myStream->nmsgs) {
envelope = mail_fetchenvelope(myStream, msgno);
}
}
