diff options
author | Oleg Oshmyan <chortos@inbox.lv> | 2014-02-12 17:00:14 +0000 |
---|---|---|
committer | Oneric <oneric@oneric.stub> | 2022-09-29 20:00:35 +0200 |
commit | 486fb4a871b50bd2a7e416266ed3e24cae2d3d2b (patch) | |
tree | dbf4d2345d4147f67284c0b0c81a61964dbca4e2 | |
parent | 5f57443f1784434fe8961275da08be6d6febc688 (diff) | |
download | libass-486fb4a871b50bd2a7e416266ed3e24cae2d3d2b.tar.bz2 libass-486fb4a871b50bd2a7e416266ed3e24cae2d3d2b.tar.xz |
Trim trailing whitespace from Dialogue lines early
Trailing "\N " no longer produces an empty line.
This matches VSFilter.
Use a pointer to one past the last character rather than to the last
character itself to avoid decrementing the pointer when it points
to the first character, which has undefined behavior.
Resolves: https://github.com/libass/libass/pull/47
-rw-r--r-- | libass/ass.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/libass/ass.c b/libass/ass.c index 41f72d6..5ec8a95 100644 --- a/libass/ass.c +++ b/libass/ass.c @@ -349,12 +349,12 @@ static int process_event_tail(ASS_Track *track, ASS_Event *event, while (1) { NEXT(q, tname); if (ass_strcasecmp(tname, "Text") == 0) { - char *last; event->Text = strdup(p); if (event->Text && *event->Text != 0) { - last = event->Text + strlen(event->Text) - 1; - if (last >= event->Text && *last == '\r') - *last = 0; + char *end = event->Text + strlen(event->Text); + while (end > event->Text && + (end[-1] == '\r' || end[-1] == '\t' || end[-1] == ' ')) + *--end = 0; } event->Duration -= event->Start; free(format); |