<<< Date Index >>>     <<< Thread Index >>>

[PATCH 06 of 16] ctx might be null. Check it earlier



1 file changed, 6 insertions(+), 4 deletions(-)
flags.c |   10 ++++++----


# HG changeset patch
# User Erik Hovland <erik@xxxxxxxxxxx>
# Date 1236891080 25200
# Branch HEAD
# Node ID 43c02f38d2127c88da18495a6c9c7c1bf5e007a7
# Parent  d56f727afd7dcb5f95d4d82fa262699c707d8844
ctx might be null. Check it earlier.

diff --git a/flags.c b/flags.c
--- a/flags.c
+++ b/flags.c
@@ -28,11 +28,13 @@
 void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx)
 {
   int changed = h->changed;
-  int deleted = ctx->deleted;
-  int tagged = ctx->tagged;
-  int flagged = ctx->flagged;
+  int deleted = ctx ? ctx->deleted : 0;
+  int tagged = ctx ? ctx->tagged : 0;
+  int flagged = ctx ? ctx->flagged : 0;
   int update = 0;
 
+  if (!ctx)
+    return; /* whoops, no context - bye */
   if (ctx->readonly && flag != M_TAG)
     return; /* don't modify anything if we are read-only */
 
@@ -53,7 +55,7 @@
 #ifdef USE_IMAP
           /* deleted messages aren't treated as changed elsewhere so that the
            * purge-on-sync option works correctly. This isn't applicable here 
*/
-          if (ctx && ctx->magic == M_IMAP)
+          if (ctx->magic == M_IMAP)
           {
             h->changed = 1;
            if (upd_ctx) ctx->changed = 1;