Diff of /cg/casn/casn.c [3d7dba] .. [84adc4] Maximize Restore

  Switch to side-by-side view

--- a/cg/casn/casn.c
+++ b/cg/casn/casn.c
@@ -265,12 +265,13 @@
     fcasnp = &casnp[1];  // first member in OF
     if (!num)
 	{
-	tcasnp = fcasnp->ptr;  // mark second for deletion
+	tcasnp = fcasnp->ptr;  // mark second for deletion (after it's copied into the first's place)
         _clear_casn(fcasnp, ~(ASN_FILLED_FLAG));
-        if (tcasnp->ptr)   // if second is not last
+        if (tcasnp)   // if first is not last
+            {
             copy_casn(fcasnp, tcasnp); //copy second to first
-        else casnp->flags &= ~(ASN_FILLED_FLAG | ASN_CHOSEN_FLAG);
-        fcasnp->ptr = tcasnp->ptr;  // make first point to where 2nd did
+            fcasnp->ptr = tcasnp->ptr;  // make first point to where 2nd did
+            }
 	}
     else
         {
@@ -278,11 +279,14 @@
         tcasnp = pcasnp->ptr;
         pcasnp->ptr = tcasnp->ptr;
         }
-    _clear_casn(tcasnp, ~(ASN_FILLED_FLAG));  // clearing is enough.
+    if (tcasnp)
+        {
+        _clear_casn(tcasnp, ~(ASN_FILLED_FLAG));  // clearing is enough.
                          // Deleting would free definers
                          // in lower OF that should only be deleted when
                          // the lcasnp is deleted
-    _free_it(tcasnp);
+        _free_it(tcasnp);
+        }
     casnp->num_items--;
     return num;
     }