summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/misc.c b/misc.c
index 4150a9d..bf7781b 100644
--- a/misc.c
+++ b/misc.c
@@ -103,8 +103,9 @@ int delm_span(char *str, const char delm) {
int sanitize_strlen(char *str) {
int len = 0;
while (*str != '\0') {
- const int tok_len = strcspn(str, " .");
- const char delm = str[tok_len];
+ const int tok_span = strcspn(str, " .");
+ const int tok_len = (tok_span) ? tok_span : 1;
+ const char delm = (tok_span) ? str[tok_len] : '\0';
const int span_len = (delm != '\0') ? delm_span(&str[tok_len+1], delm) : 0;
str += (tok_len + span_len);
len += tok_len;
@@ -117,8 +118,9 @@ char *sanitize_str(char *str) {
char *san_str = calloc(len+1, sizeof(char));
char *tmp = san_str;
while (*str != '\0' && tmp < &san_str[len]) {
- const int tok_len = strcspn(str, " .");
- const char delm = str[tok_len];
+ const int tok_span = strcspn(str, " .");
+ const int tok_len = (tok_span) ? tok_span : 1;
+ const char delm = (tok_span) ? str[tok_len] : '\0';
const int span_len = (delm != '\0') ? delm_span(&str[tok_len+1], delm) : 0;
memcpy(tmp, str, tok_len);
tmp += tok_len;