diff options
Diffstat (limited to 'src/nvim/hardcopy.c')
-rw-r--r-- | src/nvim/hardcopy.c | 54 |
1 files changed, 37 insertions, 17 deletions
diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 916d27a964..c2dc6231f1 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -23,7 +23,6 @@ #include "nvim/memline.h" #include "nvim/memory.h" #include "nvim/message.h" -#include "nvim/misc2.h" #include "nvim/garray.h" #include "nvim/option.h" #include "nvim/path.h" @@ -270,17 +269,25 @@ char_u *parse_printmbfont(void) * Returns an error message for an illegal option, NULL otherwise. * Only used for the printer at the moment... */ -static char_u *parse_list_options(char_u *option_str, option_table_T *table, int table_size) +static char_u *parse_list_options(char_u *option_str, option_table_T *table, + size_t table_size) { + option_table_T *old_opts; + char_u *ret = NULL; char_u *stringp; char_u *colonp; char_u *commap; char_u *p; - int idx = 0; /* init for GCC */ + size_t idx = 0; // init for GCC int len; - for (idx = 0; idx < table_size; ++idx) - table[idx].present = FALSE; + // Save the old values, so that they can be restored in case of an error. + old_opts = (option_table_T *)xmalloc(sizeof(option_table_T) * table_size); + + for (idx = 0; idx < table_size; idx++) { + old_opts[idx] = table[idx]; + table[idx].present = false; + } /* * Repeat for all comma separated parts. @@ -288,8 +295,10 @@ static char_u *parse_list_options(char_u *option_str, option_table_T *table, int stringp = option_str; while (*stringp) { colonp = vim_strchr(stringp, ':'); - if (colonp == NULL) - return (char_u *)N_("E550: Missing colon"); + if (colonp == NULL) { + ret = (char_u *)N_("E550: Missing colon"); + break; + } commap = vim_strchr(stringp, ','); if (commap == NULL) commap = option_str + STRLEN(option_str); @@ -300,15 +309,19 @@ static char_u *parse_list_options(char_u *option_str, option_table_T *table, int if (STRNICMP(stringp, table[idx].name, len) == 0) break; - if (idx == table_size) - return (char_u *)N_("E551: Illegal component"); + if (idx == table_size) { + ret = (char_u *)N_("E551: Illegal component"); + break; + } p = colonp + 1; table[idx].present = TRUE; if (table[idx].hasnum) { - if (!ascii_isdigit(*p)) - return (char_u *)N_("E552: digit expected"); + if (!ascii_isdigit(*p)) { + ret = (char_u *)N_("E552: digit expected"); + break; + } table[idx].number = getdigits_int(&p); } @@ -321,7 +334,15 @@ static char_u *parse_list_options(char_u *option_str, option_table_T *table, int ++stringp; } - return NULL; + if (ret != NULL) { + // Restore old options in case of error + for (idx = 0; idx < table_size; idx++) { + table[idx] = old_opts[idx]; + } + } + + xfree(old_opts); + return ret; } @@ -1523,11 +1544,10 @@ static int prt_find_resource(char *name, struct prt_ps_resource_S *resource) /* Look for named resource file in runtimepath */ STRCPY(buffer, "print"); add_pathsep((char *)buffer); - vim_strcat(buffer, (char_u *)name, MAXPATHL); - vim_strcat(buffer, (char_u *)".ps", MAXPATHL); + xstrlcat((char *)buffer, name, MAXPATHL); + xstrlcat((char *)buffer, ".ps", MAXPATHL); resource->filename[0] = NUL; - retval = (do_in_runtimepath(buffer, FALSE, prt_resource_name, - resource->filename) + retval = (do_in_runtimepath(buffer, 0, prt_resource_name, resource->filename) && resource->filename[0] != NUL); xfree(buffer); return retval; @@ -2107,7 +2127,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) props = enc_canon_props(p_encoding); if (!(props & ENC_8BIT) && ((*p_pmcs != NUL) || !(props & ENC_UNICODE))) { p_mbenc_first = NULL; - int effective_cmap; + int effective_cmap = 0; for (cmap = 0; cmap < (int)ARRAY_SIZE(prt_ps_mbfonts); cmap++) if (prt_match_encoding((char *)p_encoding, &prt_ps_mbfonts[cmap], &p_mbenc)) { |