return true;
}
-static char *_strchr_with_nth(char *s, int c, int nth)
+static char *_strchr_with_nth(char *end_pointer, char *s, int c, int nth)
{
char *cursor = s;
while (*cursor) {
+ if (end_pointer <= cursor) {
+ ERR("over end");
+ return end_pointer;
+ }
if (*cursor == c)
nth--;
return cursor;
}
-static char *_strrchr_with_nth(char *ori, char *s, int c, int nth)
+static char *_strrchr_with_nth(char *start_pointer, char *s, int c, int nth)
{
char *cursor = s;
while (*cursor) {
- if (cursor <= ori) {
+ if (cursor <= start_pointer) {
/* LCOV_EXCL_START */
- ERR("over");
- return ori;
+ ERR("over start");
+ return start_pointer;
/* LCOV_EXCL_STOP */
}
-
if (*cursor == c)
nth--;
/* LCOV_EXCL_STOP */
}
+ /* keyword length could be changed when chosung is inserted.
+ * so length could be calculated again manually.
+ */
char *keyword_start = NULL;
snprintf(mod_temp, len_offset + 1, "%s", temp);
len_print = len_offset;
- len_print += snprintf(mod_temp + len_print, len_full - len_print,
- "%s", start_match);
+ len_print += snprintf(mod_temp + len_print, len_full - len_print, "%s", start_match);
keyword_start = mod_temp + len_print;
snprintf(mod_temp + len_print, len_keyword + 1, "%s", temp + len_offset);
len_print += len_keyword;
return mod_temp;
char *cursor = NULL;
- cursor = _strchr_with_nth(keyword_start, ' ', token_number);
+ cursor = _strchr_with_nth(mod_temp + len_full, keyword_start, ' ', token_number);
*cursor = '\0';
cursor = _strrchr_with_nth(mod_temp, keyword_start, ' ', token_number);
memcpy(mod_temp, cursor, len_full);