patch 9.0.1275: the code for setting options is too complicated

Problem:    The code for setting options is too complicated.
Solution:   Refactor the do_set() function. (Yegappan Lakshmanan, Lewis
            Russell, closes #11932)
diff --git a/src/optionstr.c b/src/optionstr.c
index 46e9ac0..d218d56 100644
--- a/src/optionstr.c
+++ b/src/optionstr.c
@@ -680,7 +680,8 @@
 	// Both 'term' and 'ttytype' point to T_NAME, only set the
 	// P_ALLOCED flag on 'term'.
 	*opt_idx = findoption((char_u *)"term");
-	*free_oldval = (get_option_flags(*opt_idx) & P_ALLOCED);
+	if (*opt_idx >= 0)
+	    *free_oldval = (get_option_flags(*opt_idx) & P_ALLOCED);
     }
 
     return errmsg;