aboutsummaryrefslogtreecommitdiff
path: root/src/misc2.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc2.c')
-rw-r--r--src/misc2.c113
1 files changed, 50 insertions, 63 deletions
diff --git a/src/misc2.c b/src/misc2.c
index fe80e0bbad..997fafc7ff 100644
--- a/src/misc2.c
+++ b/src/misc2.c
@@ -233,9 +233,6 @@ coladvance2 (
char_u *newline = alloc(idx + correct + 1);
int t;
- if (newline == NULL)
- return FAIL;
-
for (t = 0; t < idx; ++t)
newline[t] = line[t];
@@ -260,8 +257,6 @@ coladvance2 (
return FAIL;
newline = alloc(linelen + csize);
- if (newline == NULL)
- return FAIL;
for (t = 0; t < linelen; t++) {
if (t != idx)
@@ -623,10 +618,8 @@ char_u *vim_strnsave(char_u *string, int len)
char_u *p;
p = alloc((unsigned)(len + 1));
- if (p != NULL) {
- STRNCPY(p, string, len);
- p[len] = NUL;
- }
+ STRNCPY(p, string, len);
+ p[len] = NUL;
return p;
}
@@ -668,21 +661,20 @@ char_u *vim_strsave_escaped_ext(char_u *string, char_u *esc_chars, int cc, int b
++length; /* count an ordinary char */
}
escaped_string = alloc(length);
- if (escaped_string != NULL) {
- p2 = escaped_string;
- for (p = string; *p; p++) {
- if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) {
- memmove(p2, p, (size_t)l);
- p2 += l;
- p += l - 1; /* skip multibyte char */
- continue;
- }
- if (vim_strchr(esc_chars, *p) != NULL || (bsl && rem_backslash(p)))
- *p2++ = cc;
- *p2++ = *p;
+ p2 = escaped_string;
+ for (p = string; *p; p++) {
+ if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) {
+ memmove(p2, p, (size_t)l);
+ p2 += l;
+ p += l - 1; /* skip multibyte char */
+ continue;
}
- *p2 = NUL;
+ if (vim_strchr(esc_chars, *p) != NULL || (bsl && rem_backslash(p)))
+ *p2++ = cc;
+ *p2++ = *p;
}
+ *p2 = NUL;
+
return escaped_string;
}
@@ -736,43 +728,41 @@ char_u *vim_strsave_shellescape(char_u *string, int do_special)
/* Allocate memory for the result and fill it. */
escaped_string = alloc(length);
- if (escaped_string != NULL) {
- d = escaped_string;
+ d = escaped_string;
- /* add opening quote */
- *d++ = '\'';
+ /* add opening quote */
+ *d++ = '\'';
- for (p = string; *p != NUL; ) {
- if (*p == '\'') {
- *d++ = '\'';
- *d++ = '\\';
- *d++ = '\'';
- *d++ = '\'';
- ++p;
- continue;
- }
- if (*p == '\n' || (*p == '!' && (csh_like || do_special))) {
+ for (p = string; *p != NUL; ) {
+ if (*p == '\'') {
+ *d++ = '\'';
+ *d++ = '\\';
+ *d++ = '\'';
+ *d++ = '\'';
+ ++p;
+ continue;
+ }
+ if (*p == '\n' || (*p == '!' && (csh_like || do_special))) {
+ *d++ = '\\';
+ if (csh_like && do_special)
*d++ = '\\';
- if (csh_like && do_special)
- *d++ = '\\';
+ *d++ = *p++;
+ continue;
+ }
+ if (do_special && find_cmdline_var(p, &l) >= 0) {
+ *d++ = '\\'; /* insert backslash */
+ while (--l >= 0) /* copy the var */
*d++ = *p++;
- continue;
- }
- if (do_special && find_cmdline_var(p, &l) >= 0) {
- *d++ = '\\'; /* insert backslash */
- while (--l >= 0) /* copy the var */
- *d++ = *p++;
- continue;
- }
-
- MB_COPY_CHAR(p, d);
+ continue;
}
- /* add terminating quote and finish with a NUL */
- *d++ = '\'';
- *d = NUL;
+ MB_COPY_CHAR(p, d);
}
+ /* add terminating quote and finish with a NUL */
+ *d++ = '\'';
+ *d = NUL;
+
return escaped_string;
}
@@ -847,8 +837,6 @@ char_u *strup_save(char_u *orig)
newl = utf_char2len(uc);
if (newl != l) {
s = alloc((unsigned)STRLEN(res) + 1 + newl - l);
- if (s == NULL)
- break;
memmove(s, res, p - res);
STRCPY(s + (p - res) + newl, p + l);
p = s + (p - res);
@@ -1452,18 +1440,17 @@ char_u *read_string(FILE *fd, int cnt)
/* allocate memory */
str = alloc((unsigned)cnt + 1);
- if (str != NULL) {
- /* Read the string. Quit when running into the EOF. */
- for (i = 0; i < cnt; ++i) {
- c = getc(fd);
- if (c == EOF) {
- vim_free(str);
- return NULL;
- }
- str[i] = c;
+ /* Read the string. Quit when running into the EOF. */
+ for (i = 0; i < cnt; ++i) {
+ c = getc(fd);
+ if (c == EOF) {
+ vim_free(str);
+ return NULL;
}
- str[i] = NUL;
+ str[i] = c;
}
+ str[i] = NUL;
+
return str;
}