mirror of
https://github.com/irssi/irssi.git
synced 2024-10-27 05:20:20 -04:00
Avoid unnecessary splitting of lines
`split_line_end' could force lines to be unnecessarily split. This commit fixes the problem by making sure that the last line isn't shorter than `split_line_end'.
This commit is contained in:
parent
5c05c854dc
commit
281c6d437d
@ -81,7 +81,7 @@ static char **split_line(const SERVER_REC *server, const char *line,
|
||||
const char *end = settings_get_str("split_line_end");
|
||||
char *recoded_start = recode_out(server, start, target);
|
||||
char *recoded_end = recode_out(server, end, target);
|
||||
char **lines;
|
||||
char **lines = NULL;
|
||||
int i;
|
||||
|
||||
/*
|
||||
@ -90,10 +90,8 @@ static char **split_line(const SERVER_REC *server, const char *line,
|
||||
* the code much simpler. It's worth it.
|
||||
*/
|
||||
len -= strlen(recoded_start) + strlen(recoded_end);
|
||||
g_free(recoded_start);
|
||||
g_free(recoded_end);
|
||||
if (len <= 0)
|
||||
return NULL; /* There is no room for anything. */
|
||||
goto out; /* There is no room for anything. */
|
||||
|
||||
lines = recode_split(server, line, target, len);
|
||||
for (i = 0; lines[i] != NULL; i++) {
|
||||
@ -106,11 +104,36 @@ static char **split_line(const SERVER_REC *server, const char *line,
|
||||
if (lines[i + 1] != NULL && *end != '\0') {
|
||||
/* Not the last line. */
|
||||
char *tmp = lines[i];
|
||||
|
||||
if (lines[i + 2] == NULL) {
|
||||
/* Next to last line. Check if we have room
|
||||
* to append the last line to the current line,
|
||||
* to avoid an unnecessary line break.
|
||||
*/
|
||||
char *recoded_l = recode_out(server,
|
||||
lines[i+1],
|
||||
target);
|
||||
if (strlen(recoded_l) <= strlen(recoded_end)) {
|
||||
lines[i] = g_strconcat(tmp, lines[i+1],
|
||||
NULL);
|
||||
g_free_and_null(lines[i+1]);
|
||||
lines = g_renew(char *, lines, i + 2);
|
||||
|
||||
g_free(recoded_l);
|
||||
g_free(tmp);
|
||||
break;
|
||||
}
|
||||
g_free(recoded_l);
|
||||
}
|
||||
|
||||
lines[i] = g_strconcat(tmp, end, NULL);
|
||||
g_free(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
g_free(recoded_start);
|
||||
g_free(recoded_end);
|
||||
return lines;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user