strings: Enable -Wconvert.

This commit is contained in:
Scott Prager
2014-11-19 15:23:11 -05:00
parent ecf81c3f20
commit f75de5e671
4 changed files with 27 additions and 29 deletions

View File

@@ -81,7 +81,6 @@ set(CONV_SOURCES
search.c search.c
sha256.c sha256.c
spell.c spell.c
strings.c
syntax.c syntax.c
tag.c tag.c
term.c term.c

View File

@@ -1813,10 +1813,10 @@ void ex_loadkeymap(exarg_T *eap)
if ((*p != '"') && (*p != NUL)) { if ((*p != '"') && (*p != NUL)) {
kmap_T *kp = GA_APPEND_VIA_PTR(kmap_T, &curbuf->b_kmap_ga); kmap_T *kp = GA_APPEND_VIA_PTR(kmap_T, &curbuf->b_kmap_ga);
s = skiptowhite(p); s = skiptowhite(p);
kp->from = vim_strnsave(p, (int)(s - p)); kp->from = vim_strnsave(p, (size_t)(s - p));
p = skipwhite(s); p = skipwhite(s);
s = skiptowhite(p); s = skiptowhite(p);
kp->to = vim_strnsave(p, (int)(s - p)); kp->to = vim_strnsave(p, (size_t)(s - p));
if ((STRLEN(kp->from) + STRLEN(kp->to) >= KMAP_LLEN) if ((STRLEN(kp->from) + STRLEN(kp->to) >= KMAP_LLEN)
|| (*kp->from == NUL) || (*kp->from == NUL)

View File

@@ -43,7 +43,7 @@ char *os_getenvname_at_index(size_t index)
if (str == NULL) { if (str == NULL) {
return NULL; return NULL;
} }
int namesize = 0; size_t namesize = 0;
while (str[namesize] != '=' && str[namesize] != NUL) { while (str[namesize] != '=' && str[namesize] != NUL) {
namesize++; namesize++;
} }

View File

@@ -62,7 +62,7 @@ char_u *vim_strsave(const char_u *string)
* The allocated memory always has size "len + 1", also when "string" is * The allocated memory always has size "len + 1", also when "string" is
* shorter. * shorter.
*/ */
char_u *vim_strnsave(const char_u *string, int len) char_u *vim_strnsave(const char_u *string, size_t len)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
{ {
return (char_u *)strncpy(xmallocz(len), (char *)string, len); return (char_u *)strncpy(xmallocz(len), (char *)string, len);
@@ -75,29 +75,27 @@ char_u *vim_strnsave(const char_u *string, int len)
char_u *vim_strsave_escaped(const char_u *string, const char_u *esc_chars) char_u *vim_strsave_escaped(const char_u *string, const char_u *esc_chars)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
{ {
return vim_strsave_escaped_ext(string, esc_chars, '\\', FALSE); return vim_strsave_escaped_ext(string, esc_chars, '\\', false);
} }
/* /*
* Same as vim_strsave_escaped(), but when "bsl" is TRUE also escape * Same as vim_strsave_escaped(), but when "bsl" is true also escape
* characters where rem_backslash() would remove the backslash. * characters where rem_backslash() would remove the backslash.
* Escape the characters with "cc". * Escape the characters with "cc".
*/ */
char_u *vim_strsave_escaped_ext(const char_u *string, const char_u *esc_chars, char_u *vim_strsave_escaped_ext(const char_u *string, const char_u *esc_chars,
int cc, int bsl) char_u cc, bool bsl)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
{ {
unsigned length;
int l;
/* /*
* First count the number of backslashes required. * First count the number of backslashes required.
* Then allocate the memory and insert them. * Then allocate the memory and insert them.
*/ */
length = 1; /* count the trailing NUL */ size_t length = 1; // count the trailing NUL
for (const char_u *p = string; *p; p++) { for (const char_u *p = string; *p; p++) {
if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) { size_t l;
length += l; /* count a multibyte char */ if (has_mbyte && (l = (size_t)(*mb_ptr2len)(p)) > 1) {
length += l; // count a multibyte char
p += l - 1; p += l - 1;
continue; continue;
} }
@@ -109,8 +107,9 @@ char_u *vim_strsave_escaped_ext(const char_u *string, const char_u *esc_chars,
char_u *escaped_string = xmalloc(length); char_u *escaped_string = xmalloc(length);
char_u *p2 = escaped_string; char_u *p2 = escaped_string;
for (const char_u *p = string; *p; p++) { for (const char_u *p = string; *p; p++) {
if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) { size_t l;
memmove(p2, p, (size_t)l); if (has_mbyte && (l = (size_t)(*mb_ptr2len)(p)) > 1) {
memcpy(p2, p, l);
p2 += l; p2 += l;
p += l - 1; /* skip multibyte char */ p += l - 1; /* skip multibyte char */
continue; continue;
@@ -225,7 +224,7 @@ char_u *vim_strsave_up(const char_u *string)
* Like vim_strnsave(), but make all characters uppercase. * Like vim_strnsave(), but make all characters uppercase.
* This uses ASCII lower-to-upper case translation, language independent. * This uses ASCII lower-to-upper case translation, language independent.
*/ */
char_u *vim_strnsave_up(const char_u *string, int len) char_u *vim_strnsave_up(const char_u *string, size_t len)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
{ {
char_u *p1 = vim_strnsave(string, len); char_u *p1 = vim_strnsave(string, len);
@@ -240,12 +239,12 @@ void vim_strup(char_u *p)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
char_u *p2; char_u *p2;
int c; char_u c;
if (p != NULL) { if (p != NULL) {
p2 = p; p2 = p;
while ((c = *p2) != NUL) while ((c = *p2) != NUL)
*p2++ = (c < 'a' || c > 'z') ? c : (c - 0x20); *p2++ = (char_u)((c < 'a' || c > 'z') ? c : c - 0x20);
} }
} }
@@ -272,8 +271,8 @@ char_u *strup_save(const char_u *orig)
int newl = utf_char2len(uc); int newl = utf_char2len(uc);
if (newl != l) { if (newl != l) {
// TODO(philix): use xrealloc() in strup_save() // TODO(philix): use xrealloc() in strup_save()
char_u *s = xmalloc(STRLEN(res) + 1 + newl - l); char_u *s = xmalloc(STRLEN(res) + (size_t)(1 + newl - l));
memmove(s, res, p - res); memcpy(s, res, (size_t)(p - res));
STRCPY(s + (p - res) + newl, p + l); STRCPY(s + (p - res) + newl, p + l);
p = s + (p - res); p = s + (p - res);
free(res); free(res);
@@ -285,7 +284,7 @@ char_u *strup_save(const char_u *orig)
} else if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) } else if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1)
p += l; /* skip multi-byte character */ p += l; /* skip multi-byte character */
else { else {
*p = TOUPPER_LOC(*p); /* note that toupper() can be a macro */ *p = (char_u) TOUPPER_LOC(*p); // note that toupper() can be a macro
p++; p++;
} }
} }
@@ -310,7 +309,7 @@ void copy_spaces(char_u *ptr, size_t count)
* Copy a character a number of times. * Copy a character a number of times.
* Does not work for multi-byte characters! * Does not work for multi-byte characters!
*/ */
void copy_chars(char_u *ptr, size_t count, int c) void copy_chars(char_u *ptr, size_t count, char_u c)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
size_t i = count; size_t i = count;
@@ -498,7 +497,7 @@ char_u *vim_strrchr(const char_u *string, int c)
* Vim has its own isspace() function, because on some machines isspace() * Vim has its own isspace() function, because on some machines isspace()
* can't handle characters above 128. * can't handle characters above 128.
*/ */
int vim_isspace(int x) bool vim_isspace(int x)
FUNC_ATTR_CONST FUNC_ATTR_CONST
{ {
return (x >= 9 && x <= 13) || x == ' '; return (x >= 9 && x <= 13) || x == ' ';
@@ -523,10 +522,10 @@ void sort_strings(char_u **files, int count)
} }
/* /*
* Return TRUE if string "s" contains a non-ASCII character (128 or higher). * Return true if string "s" contains a non-ASCII character (128 or higher).
* When "s" is NULL FALSE is returned. * When "s" is NULL false is returned.
*/ */
int has_non_ascii(const char_u *s) bool has_non_ascii(const char_u *s)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE
{ {
const char_u *p; const char_u *p;
@@ -534,8 +533,8 @@ int has_non_ascii(const char_u *s)
if (s != NULL) if (s != NULL)
for (p = s; *p != NUL; ++p) for (p = s; *p != NUL; ++p)
if (*p >= 128) if (*p >= 128)
return TRUE; return true;
return FALSE; return false;
} }
/* /*