updated for version 7.0225
diff --git a/src/undo.c b/src/undo.c
index 88f11a3..27f04b9 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -295,6 +295,8 @@
 	    if (uhp == NULL)
 		goto nomem;
 	}
+	else
+	    uhp = NULL;
 
 	/*
 	 * If we undid more than we redid, move the entry lists before and
@@ -326,7 +328,7 @@
 	    }
 	}
 
-	if (p_ul < 0)		/* no undo at all */
+	if (uhp == NULL)		/* no undo at all */
 	{
 	    if (old_curhead != NULL)
 		u_freebranch(curbuf, old_curhead, NULL);
@@ -655,6 +657,10 @@
     int		    dosec = sec;
     int		    above = FALSE;
 
+    /* First make sure the current undoable change is synced. */
+    if (curbuf->b_u_synced == FALSE)
+	u_sync();
+
     u_newcount = 0;
     u_oldcount = 0;
     if (curbuf->b_ml.ml_flags & ML_EMPTY)