aboutsummaryrefslogtreecommitdiff
path: root/src/mbyte.c
diff options
context:
space:
mode:
authorFelipe Oliveira Carvalho <felipekde@gmail.com>2014-04-01 01:41:39 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-04-06 22:54:59 -0300
commit13848aadbfed94a62505d4e349426990c75d2ae5 (patch)
tree664873759b05c4e50e879ef7630621dc023d3b56 /src/mbyte.c
parent6bbffee0a5b4239e3177812c5f5f20133aa60fe8 (diff)
downloadrneovim-13848aadbfed94a62505d4e349426990c75d2ae5.tar.gz
rneovim-13848aadbfed94a62505d4e349426990c75d2ae5.tar.bz2
rneovim-13848aadbfed94a62505d4e349426990c75d2ae5.zip
Remove simpler cases of OOM error handling (after *alloc calls)
By simpler cases I mean cases where the OOM error is not expected to be handled by the caller of the function that calls `alloc`, `lalloc`, `xrealloc`, `xmalloc`, `alloc_clear`, and `lalloc_clear`. These are the functions that: - Do not return an allocated buffer - Have OOM as the only error condition I took note of the functions that expect the caller to handle the OOM error and will go through them to check all the callers that may be handling OOM error in future commits. I'm ignoring eval.c and ex_.c in this series of commits. eval.c will soon be obsolete and I will deal with ex_.c in later PRs.
Diffstat (limited to 'src/mbyte.c')
-rw-r--r--src/mbyte.c85
1 files changed, 38 insertions, 47 deletions
diff --git a/src/mbyte.c b/src/mbyte.c
index fff953ebfc..756254076a 100644
--- a/src/mbyte.c
+++ b/src/mbyte.c
@@ -3334,49 +3334,47 @@ char_u * enc_canonize(char_u *enc)
/* copy "enc" to allocated memory, with room for two '-' */
r = alloc((unsigned)(STRLEN(enc) + 3));
- if (r != NULL) {
- /* Make it all lower case and replace '_' with '-'. */
- p = r;
- for (s = enc; *s != NUL; ++s) {
- if (*s == '_')
- *p++ = '-';
- else
- *p++ = TOLOWER_ASC(*s);
- }
- *p = NUL;
+ /* Make it all lower case and replace '_' with '-'. */
+ p = r;
+ for (s = enc; *s != NUL; ++s) {
+ if (*s == '_')
+ *p++ = '-';
+ else
+ *p++ = TOLOWER_ASC(*s);
+ }
+ *p = NUL;
- /* Skip "2byte-" and "8bit-". */
- p = enc_skip(r);
+ /* Skip "2byte-" and "8bit-". */
+ p = enc_skip(r);
- /* Change "microsoft-cp" to "cp". Used in some spell files. */
- if (STRNCMP(p, "microsoft-cp", 12) == 0)
- STRMOVE(p, p + 10);
+ /* Change "microsoft-cp" to "cp". Used in some spell files. */
+ if (STRNCMP(p, "microsoft-cp", 12) == 0)
+ STRMOVE(p, p + 10);
- /* "iso8859" -> "iso-8859" */
- if (STRNCMP(p, "iso8859", 7) == 0) {
- STRMOVE(p + 4, p + 3);
- p[3] = '-';
- }
+ /* "iso8859" -> "iso-8859" */
+ if (STRNCMP(p, "iso8859", 7) == 0) {
+ STRMOVE(p + 4, p + 3);
+ p[3] = '-';
+ }
- /* "iso-8859n" -> "iso-8859-n" */
- if (STRNCMP(p, "iso-8859", 8) == 0 && p[8] != '-') {
- STRMOVE(p + 9, p + 8);
- p[8] = '-';
- }
+ /* "iso-8859n" -> "iso-8859-n" */
+ if (STRNCMP(p, "iso-8859", 8) == 0 && p[8] != '-') {
+ STRMOVE(p + 9, p + 8);
+ p[8] = '-';
+ }
- /* "latin-N" -> "latinN" */
- if (STRNCMP(p, "latin-", 6) == 0)
- STRMOVE(p + 5, p + 6);
-
- if (enc_canon_search(p) >= 0) {
- /* canonical name can be used unmodified */
- if (p != r)
- STRMOVE(r, p);
- } else if ((i = enc_alias_search(p)) >= 0) {
- /* alias recognized, get canonical name */
- vim_free(r);
- r = vim_strsave((char_u *)enc_canon_table[i].name);
- }
+ /* "latin-N" -> "latinN" */
+ if (STRNCMP(p, "latin-", 6) == 0)
+ STRMOVE(p + 5, p + 6);
+
+ if (enc_canon_search(p) >= 0) {
+ /* canonical name can be used unmodified */
+ if (p != r)
+ STRMOVE(r, p);
+ } else if ((i = enc_alias_search(p)) >= 0) {
+ /* alias recognized, get canonical name */
+ vim_free(r);
+ r = vim_strsave((char_u *)enc_canon_table[i].name);
}
return r;
}
@@ -3537,7 +3535,7 @@ static char_u * iconv_string(vimconv_T *vcp, char_u *str, int slen, int *unconvl
* increase the buffer size. */
len = len + fromlen * 2 + 40;
p = alloc((unsigned)len);
- if (p != NULL && done > 0)
+ if (done > 0)
memmove(p, result, done);
vim_free(result);
result = p;
@@ -3856,8 +3854,7 @@ int convert_input_safe(ptr, len, maxlen, restp, restlenp)
if (unconvertlen > 0) {
/* Move the unconverted characters to allocated memory. */
*restp = alloc(unconvertlen);
- if (*restp != NULL)
- memmove(*restp, ptr + len - unconvertlen, unconvertlen);
+ memmove(*restp, ptr + len - unconvertlen, unconvertlen);
*restlenp = unconvertlen;
}
memmove(ptr, d, dlen);
@@ -3913,8 +3910,6 @@ char_u * string_convert_ext(vcp, ptr, lenp, unconvlenp)
switch (vcp->vc_type) {
case CONV_TO_UTF8: /* latin1 to utf-8 conversion */
retval = alloc(len * 2 + 1);
- if (retval == NULL)
- break;
d = retval;
for (i = 0; i < len; ++i) {
c = ptr[i];
@@ -3932,8 +3927,6 @@ char_u * string_convert_ext(vcp, ptr, lenp, unconvlenp)
case CONV_9_TO_UTF8: /* latin9 to utf-8 conversion */
retval = alloc(len * 3 + 1);
- if (retval == NULL)
- break;
d = retval;
for (i = 0; i < len; ++i) {
c = ptr[i];
@@ -3957,8 +3950,6 @@ char_u * string_convert_ext(vcp, ptr, lenp, unconvlenp)
case CONV_TO_LATIN1: /* utf-8 to latin1 conversion */
case CONV_TO_LATIN9: /* utf-8 to latin9 conversion */
retval = alloc(len + 1);
- if (retval == NULL)
- break;
d = retval;
for (i = 0; i < len; ++i) {
l = utf_ptr2len_len(ptr + i, len - i);