summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorIku <iku@yokattana.com>2017-02-08 12:14:35 +0100
committerIku <iku@yokattana.com>2017-02-08 12:19:39 +0100
commit000265bfbf181c41bd932e4bf48e187df2496cb6 (patch)
treec0bfb36e7a1b895c96e9957de0d33dee87752cd5 /src/utils
parentb9486522575038f93a7dc08ce8860ef7a270ba4b (diff)
Remove problematic split() function
Major issues with split(): 1. It allocates too many array entries 2. It will seek into out of bounds memory 3. It seeds to many nulls See https://github.com/andmarti1424/sc-im/issues/116 for details. This commit removes split() and replaces its use with some stdlib functions. Tests performed: - ./scim --half_page_scroll (verify using :set) - ./scim --half_page_scroll=2 (verify using :set) - !ls -l
Diffstat (limited to 'src/utils')
-rwxr-xr-xsrc/utils/string.c27
-rwxr-xr-xsrc/utils/string.h1
2 files changed, 0 insertions, 28 deletions
diff --git a/src/utils/string.c b/src/utils/string.c
index 753f37f..524637a 100755
--- a/src/utils/string.c
+++ b/src/utils/string.c
@@ -175,33 +175,6 @@ int is_idchar (int d) {
return 0;
}
-char ** split(char *string, const char delimiter, int lastnull) {
- int length = 0, count = 0, i = 0, j = 0;
- while(*(string++)) {
- if (*string == delimiter) count++;
- length++;
- }
- string -= (length + 1); // string was incremented one more than length
- char **array = (char **)malloc(sizeof(char *) * (length + 1 + lastnull));
- char ** base = array;
- for(i = 0; i < (count + 1); i++) {
- j = 0;
- while(string[j] != delimiter) j++;
- j++;
- * array = (char *) malloc(sizeof(char) * j);
- memcpy(*array, string, (j-1));
- (*array)[j-1] = '\0';
- string += j;
- array++;
- }
- if (lastnull) {
- *array = NULL;
- array++;
- }
- *array = '\0';
- return base;
-}
-
char * rtrim(char * string, char junk) {
char * original = string + strlen(string);
while(*--original == junk);
diff --git a/src/utils/string.h b/src/utils/string.h
index be54d9d..4dab3f9 100755
--- a/src/utils/string.h
+++ b/src/utils/string.h
@@ -16,7 +16,6 @@ void subst(char * s, char from, char to);
int is_idchar (int d);
int str_in_str(char * s, char * b);
int wstr_in_wstr(wchar_t * s, wchar_t * b);
-char ** split(char *string, const char delimiter, int lastnull);
char * ltrim(char *string, char junk);
char * rtrim(char * string, char junk);
int isnumeric(char * string);