diff --git a/src/option.c b/src/option.c
--- a/src/option.c
+++ b/src/option.c
@@ -7570,8 +7570,9 @@
     }
 
 #ifdef FEAT_PERSISTENT_UNDO
-    /* 'undofile' */
-    else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
+    /* 'undofile' was set */
+    else if (((int *)varp == &curbuf->b_p_udf && curbuf->b_p_udf)
+	    || ((int *)varp == &p_udf && p_udf))
     {
 	char_u	hash[UNDO_HASH_SIZE];
 	buf_T	*save_curbuf = curbuf;
@@ -7580,8 +7581,8 @@
 	{
 	    /* When 'undofile' is set globally: for every buffer, otherwise
 	     * only for the current buffer: Try to read in the undofile, if
-	     * one exists and the buffer wasn't changed and the buffer was
-	     * loaded. */
+	     * one exists, the buffer wasn't changed and the buffer was
+	     * loaded */
 	    if ((curbuf == save_curbuf
 				|| (opt_flags & OPT_GLOBAL) || opt_flags == 0)
 		    && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
