mirror of
https://github.com/neovim/neovim.git
synced 2025-10-16 06:46:07 +00:00
No OOM in enc_canonize()
Fix a `return FAIL` that should be `return NULL` in `enc_locale()`
This commit is contained in:
@@ -3012,8 +3012,6 @@ void ex_scriptencoding(exarg_T *eap)
|
||||
|
||||
if (*eap->arg != NUL) {
|
||||
name = enc_canonize(eap->arg);
|
||||
if (name == NULL) /* out of memory */
|
||||
return;
|
||||
} else
|
||||
name = eap->arg;
|
||||
|
||||
|
@@ -2087,10 +2087,7 @@ void set_forced_fenc(exarg_T *eap)
|
||||
{
|
||||
if (eap->force_enc != 0) {
|
||||
char_u *fenc = enc_canonize(eap->cmd + eap->force_enc);
|
||||
|
||||
if (fenc != NULL)
|
||||
set_string_option_direct((char_u *)"fenc", -1,
|
||||
fenc, OPT_FREE|OPT_LOCAL, 0);
|
||||
set_string_option_direct((char_u *)"fenc", -1, fenc, OPT_FREE|OPT_LOCAL, 0);
|
||||
free(fenc);
|
||||
}
|
||||
}
|
||||
|
@@ -84,6 +84,7 @@
|
||||
#include "nvim/charset.h"
|
||||
#include "nvim/cursor.h"
|
||||
#include "nvim/fileio.h"
|
||||
#include "nvim/func_attr.h"
|
||||
#include "nvim/memline.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
@@ -3308,24 +3309,23 @@ char_u * enc_skip(char_u *p)
|
||||
* Find the canonical name for encoding "enc".
|
||||
* When the name isn't recognized, returns "enc" itself, but with all lower
|
||||
* case characters and '_' replaced with '-'.
|
||||
* Returns an allocated string. NULL for out-of-memory.
|
||||
* Returns an allocated string.
|
||||
*/
|
||||
char_u * enc_canonize(char_u *enc)
|
||||
char_u *enc_canonize(char_u *enc) FUNC_ATTR_NONNULL_RET
|
||||
{
|
||||
char_u *r;
|
||||
char_u *p, *s;
|
||||
int i;
|
||||
|
||||
if (STRCMP(enc, "default") == 0) {
|
||||
/* Use the default encoding as it's found by set_init_1(). */
|
||||
r = get_encoding_default();
|
||||
char_u *r = get_encoding_default();
|
||||
if (r == NULL)
|
||||
r = (char_u *)"latin1";
|
||||
return vim_strsave(r);
|
||||
}
|
||||
|
||||
/* copy "enc" to allocated memory, with room for two '-' */
|
||||
r = xmalloc(STRLEN(enc) + 3);
|
||||
char_u *r = xmalloc(STRLEN(enc) + 3);
|
||||
/* Make it all lower case and replace '_' with '-'. */
|
||||
p = r;
|
||||
for (s = enc; *s != NUL; ++s) {
|
||||
@@ -3411,7 +3411,7 @@ char_u * enc_locale()
|
||||
s = (char *)os_getenv("LANG");
|
||||
|
||||
if (s == NULL || *s == NUL)
|
||||
return FAIL;
|
||||
return NULL;
|
||||
|
||||
/* The most generic locale format is:
|
||||
* language[_territory][.codeset][@modifier][+special][,[sponsor][_revision]]
|
||||
|
@@ -3971,10 +3971,8 @@ did_set_string_option (
|
||||
if (errmsg == NULL) {
|
||||
/* canonize the value, so that STRCMP() can be used on it */
|
||||
p = enc_canonize(*varp);
|
||||
if (p != NULL) {
|
||||
free(*varp);
|
||||
*varp = p;
|
||||
}
|
||||
free(*varp);
|
||||
*varp = p;
|
||||
if (varp == &p_enc) {
|
||||
errmsg = mb_init();
|
||||
redraw_titles();
|
||||
@@ -4000,18 +3998,8 @@ did_set_string_option (
|
||||
} else if (varp == &p_penc) {
|
||||
/* Canonize printencoding if VIM standard one */
|
||||
p = enc_canonize(p_penc);
|
||||
if (p != NULL) {
|
||||
free(p_penc);
|
||||
p_penc = p;
|
||||
} else {
|
||||
/* Ensure lower case and '-' for '_' */
|
||||
for (s = p_penc; *s != NUL; s++) {
|
||||
if (*s == '_')
|
||||
*s = '-';
|
||||
else
|
||||
*s = TOLOWER_ASC(*s);
|
||||
}
|
||||
}
|
||||
free(p_penc);
|
||||
p_penc = p;
|
||||
} else if (varp == &curbuf->b_p_keymap) {
|
||||
/* load or unload key mapping tables */
|
||||
errmsg = keymap_init();
|
||||
|
@@ -4438,7 +4438,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
|
||||
if (is_aff_rule(items, itemcnt, "SET", 2) && aff->af_enc == NULL) {
|
||||
// Setup for conversion from "ENC" to 'encoding'.
|
||||
aff->af_enc = enc_canonize(items[1]);
|
||||
if (aff->af_enc != NULL && !spin->si_ascii
|
||||
if (!spin->si_ascii
|
||||
&& convert_setup(&spin->si_conv, aff->af_enc,
|
||||
p_enc) == FAIL)
|
||||
smsg((char_u *)_("Conversion in %s not supported: from %s to %s"),
|
||||
@@ -5978,7 +5978,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname)
|
||||
// Setup for conversion to 'encoding'.
|
||||
line += 9;
|
||||
enc = enc_canonize(line);
|
||||
if (enc != NULL && !spin->si_ascii
|
||||
if (!spin->si_ascii
|
||||
&& convert_setup(&spin->si_conv, enc,
|
||||
p_enc) == FAIL)
|
||||
smsg((char_u *)_("Conversion in %s not supported: from %s to %s"),
|
||||
|
Reference in New Issue
Block a user