aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelipe Oliveira Carvalho <felipekde@gmail.com>2014-05-30 23:19:02 -0300
committerFelipe Oliveira Carvalho <felipekde@gmail.com>2014-06-16 01:36:31 -0300
commit81ca5ff126c5c0731b7eb57513f899ac6619073e (patch)
tree63784713d4e3abb32a7bf5a491a8e155171cbbce /src
parent8234f2839f78009442b4ed7bc0599e6b581d5cf8 (diff)
downloadrneovim-81ca5ff126c5c0731b7eb57513f899ac6619073e.tar.gz
rneovim-81ca5ff126c5c0731b7eb57513f899ac6619073e.tar.bz2
rneovim-81ca5ff126c5c0731b7eb57513f899ac6619073e.zip
No OOM in enc_canonize()
Fix a `return FAIL` that should be `return NULL` in `enc_locale()`
Diffstat (limited to 'src')
-rw-r--r--src/nvim/ex_cmds2.c2
-rw-r--r--src/nvim/fileio.c5
-rw-r--r--src/nvim/mbyte.c12
-rw-r--r--src/nvim/option.c20
-rw-r--r--src/nvim/spell.c4
5 files changed, 13 insertions, 30 deletions
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index 1876276e9f..17c0f3bf3e 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -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;
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index fc8ff8b987..129f1a1de2 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -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);
}
}
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index 899b94e0fb..21fdd31db1 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -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]]
diff --git a/src/nvim/option.c b/src/nvim/option.c
index b610ac463e..c14edd1a9c 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -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();
diff --git a/src/nvim/spell.c b/src/nvim/spell.c
index 8214d95c00..ca522191b9 100644
--- a/src/nvim/spell.c
+++ b/src/nvim/spell.c
@@ -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"),