Fix warnings: option.c: makeset()/put_setnum(): Various (3): FP.

Problems   : Dereference of null pointer @ 6251.
             Dereference of null pointer @ 6267.
             Dereference of null pointer @ 6351.
Diagnostic : False positive.
Rationale  : Problems occur if varp is null after
             `varp = get_varp_scope(p, opt_flags);`.
             That can only happen if option is hidden. Those are options
             that can be set (for backwards compatibility reasons) but
             that do nothing (see `:h hidden-options`,
             `:h missing-options`). In particular, even if setting them
             is allowed, value is not stored, so these options have no
             real value.
             So, suggested error paths should not occur, as checks
             comparing option value and default value should discard
             them.
Resolution : We could just `assert(varp)` before line 6235
             `varp_local = varp;`. That was tried and worked.
             But we prefer modifying the code to explicitly skip hidden
             options.
             A redundant `!istermoption(p)` is removed too (it's already
             checked by for loop condition).
This commit is contained in:
Eliseo Martínez 2014-12-17 15:25:59 +01:00
parent 10a45846dc
commit 693da00920

View File

@ -6196,15 +6196,17 @@ int makeset(FILE *fd, int opt_flags, int local_only)
int pri; int pri;
/* /*
* The options that don't have a default (terminal name, columns, lines) * Some options are never written:
* are never written. Terminal options are also not written. * - Options that don't have a default (terminal name, columns, lines).
* - Terminal options.
* - Hidden options.
*
* Do the loop over "options[]" twice: once for options with the * Do the loop over "options[]" twice: once for options with the
* P_PRI_MKRC flag and once without. * P_PRI_MKRC flag and once without.
*/ */
for (pri = 1; pri >= 0; --pri) { for (pri = 1; pri >= 0; --pri) {
for (p = &options[0]; !istermoption(p); p++) for (p = &options[0]; !istermoption(p); p++)
if (!(p->flags & P_NO_MKRC) if (!(p->flags & P_NO_MKRC)
&& !istermoption(p)
&& ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0))) { && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0))) {
/* skip global option when only doing locals */ /* skip global option when only doing locals */
if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL)) if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
@ -6215,8 +6217,11 @@ int makeset(FILE *fd, int opt_flags, int local_only)
if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB)) if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
continue; continue;
/* Global values are only written when not at the default value. */
varp = get_varp_scope(p, opt_flags); varp = get_varp_scope(p, opt_flags);
/* Hidden options are never written. */
if (!varp)
continue;
/* Global values are only written when not at the default value. */
if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp)) if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
continue; continue;