diff options
Diffstat (limited to 'src/nvim/option.c')
-rw-r--r-- | src/nvim/option.c | 73 |
1 files changed, 39 insertions, 34 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c index 2d016d8350..23a23a0814 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -363,13 +363,14 @@ typedef struct vimoption { # define ISP_LATIN1 (char_u *)"@,161-255" #define HIGHLIGHT_INIT \ - "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch," \ - "l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine," \ - "S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg," \ - "W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete," \ - "T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare," \ - "L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine," \ - "#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn" + "8:SpecialKey,~:EndOfBuffer,z:TermCursor,Z:TermCursorNC,@:NonText," \ + "d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr," \ + "N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title," \ + "v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn," \ + "A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal," \ + "B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel," \ + "x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill," \ + "!:CursorColumn,.:CursorLine,o:ColorColumn" /* * options[] is initialized here. @@ -1826,11 +1827,11 @@ void set_init_1(void) ga.ga_len += len; } if (mustfree) - free(p); + xfree(p); } if (ga.ga_data != NULL) { set_string_default("bsk", ga.ga_data); - free(ga.ga_data); + xfree(ga.ga_data); } } @@ -1884,10 +1885,10 @@ void set_init_1(void) options[opt_idx].def_val[VI_DEFAULT] = buf; options[opt_idx].flags |= P_DEF_ALLOCED; } else - free(buf); /* cannot happen */ + xfree(buf); /* cannot happen */ } if (mustfree) - free(cdpath); + xfree(cdpath); } } @@ -1957,7 +1958,7 @@ void set_init_1(void) * split P_DEF_ALLOCED in two. */ if (options[opt_idx].flags & P_DEF_ALLOCED) - free(options[opt_idx].def_val[VI_DEFAULT]); + xfree(options[opt_idx].def_val[VI_DEFAULT]); options[opt_idx].def_val[VI_DEFAULT] = p; options[opt_idx].flags |= P_DEF_ALLOCED; } @@ -1997,7 +1998,7 @@ void set_init_1(void) * for practical purposes, thus use that. It's not an alias to * still support conversion between gb18030 and utf-8. */ p_enc = vim_strsave((char_u *)"cp936"); - free(p); + xfree(p); } if (mb_init() == NULL) { opt_idx = findoption((char_u *)"encoding"); @@ -2027,7 +2028,7 @@ void set_init_1(void) #endif } else { - free(p_enc); + xfree(p_enc); // mb_init() failed; fallback to utf8 and try again. p_enc = save_enc; mb_init(); @@ -2135,7 +2136,7 @@ void set_string_default(const char *name, const char_u *val) int opt_idx = findoption((char_u *)name); if (opt_idx >= 0) { if (options[opt_idx].flags & P_DEF_ALLOCED) { - free(options[opt_idx].def_val[VI_DEFAULT]); + xfree(options[opt_idx].def_val[VI_DEFAULT]); } options[opt_idx].def_val[VI_DEFAULT] = (char_u *) xstrdup((char *) val); @@ -2275,7 +2276,7 @@ void set_init_3(void) options[idx_srr].def_val[VI_DEFAULT] = p_srr; } } - free(p); + xfree(p); } #endif @@ -2781,7 +2782,7 @@ do_set ( (char_u *)"indent,eol,start"); break; } - free(oldval); + xfree(oldval); oldval = *(char_u **)varp; } /* @@ -2878,7 +2879,7 @@ do_set ( || (flags & P_COMMA)) { s = option_expand(opt_idx, newval); if (s != NULL) { - free(newval); + xfree(newval); newlen = (unsigned)STRLEN(s) + 1; if (adding || prepending || removing) newlen += (unsigned)STRLEN(origval) + 1; @@ -3372,13 +3373,13 @@ void check_buf_options(buf_T *buf) void free_string_option(char_u *p) { if (p != empty_option) - free(p); + xfree(p); } void clear_string_option(char_u **pp) { if (*pp != empty_option) - free(*pp); + xfree(*pp); *pp = empty_option; } @@ -3767,7 +3768,7 @@ did_set_string_option ( if (errmsg == NULL) { /* canonize the value, so that STRCMP() can be used on it */ p = enc_canonize(*varp); - free(*varp); + xfree(*varp); *varp = p; if (varp == &p_enc) { errmsg = mb_init(); @@ -3794,7 +3795,7 @@ did_set_string_option ( } else if (varp == &p_penc) { /* Canonize printencoding if VIM standard one */ p = enc_canonize(p_penc); - free(p_penc); + xfree(p_penc); p_penc = p; } else if (varp == &curbuf->b_p_keymap) { /* load or unload key mapping tables */ @@ -4455,7 +4456,7 @@ skip: return e_invarg; /* illegal trailing comma as in "set cc=80," */ } - free(wp->w_p_cc_cols); + xfree(wp->w_p_cc_cols); if (count == 0) wp->w_p_cc_cols = NULL; else { @@ -4648,7 +4649,7 @@ static char_u *compile_cap_prog(synblock_T *synblock) /* Prepend a ^ so that we only match at one column */ re = concat_str((char_u *)"^", synblock->b_p_spc); synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC); - free(re); + xfree(re); if (synblock->b_cap_prog == NULL) { synblock->b_cap_prog = rp; /* restore the previous program */ return e_invarg; @@ -5929,7 +5930,7 @@ showoptions ( os_breakcheck(); } } - free(items); + xfree(items); } /* @@ -6156,10 +6157,10 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int e buf = xmalloc(MAXPATHL); home_replace(NULL, *valuep, buf, MAXPATHL, FALSE); if (put_escstr(fd, buf, 2) == FAIL) { - free(buf); + xfree(buf); return FAIL; } - free(buf); + xfree(buf); } else if (put_escstr(fd, *valuep, 2) == FAIL) return FAIL; } @@ -7437,10 +7438,10 @@ void vimrc_found(char_u *fname, char_u *envname) p = FullName_save(fname, FALSE); if (p != NULL) { vim_setenv(envname, p); - free(p); + xfree(p); } } else if (dofree) - free(p); + xfree(p); } } @@ -7607,7 +7608,7 @@ void save_file_ff(buf_T *buf) /* Only use free/alloc when necessary, they take time. */ if (buf->b_start_fenc == NULL || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0) { - free(buf->b_start_fenc); + xfree(buf->b_start_fenc); buf->b_start_fenc = vim_strsave(buf->b_p_fenc); } } @@ -7653,18 +7654,22 @@ int check_ff_value(char_u *p) * Return the effective shiftwidth value for current buffer, using the * 'tabstop' value when 'shiftwidth' is zero. */ -long get_sw_value(buf_T *buf) +int get_sw_value(buf_T *buf) { - return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts; + long result = buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts; + assert(result >= 0 && result <= INT_MAX); + return (int)result; } /* * Return the effective softtabstop value for the current buffer, using the * 'tabstop' value when 'softtabstop' is negative. */ -long get_sts_value(void) +int get_sts_value(void) { - return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts; + long result = curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts; + assert(result >= 0 && result <= INT_MAX); + return (int)result; } /* |