Gavino
29th October 2009, 09:13
Subtitle() supports a feature to allow the characters "\n" to be output inside a multi-line title, by using the escape sequence "\\n" to prevent interpretation as a line break. Thus, Subtitle("ABC\\nDEF", lsp=0) should produce the title "ABC\nDEF".
However, the code for this in Subtitle::InitAntialiaser (attributed to foxyshadis) contains a subtle flaw - it changes the text argument in situ, something that should never be done, since it means that the string literal in the script is effectively altered.
In this example,
function WTF(clip c, int y) {
Subtitle(c, "ABC\\nDEF", y=y, lsp=0)
}
BlankClip()
WTF(0)
WTF(20)
the first time the function is called, it works fine. However, the second time the literal has been changed, and the output is
AABC
DEF
The simplest code fix is to copy the text string before processing it in the multiline case, ie replace
psrc = (char *)text;
by
char *text2 = strdup(text);
if (!text2) goto GDIError;
psrc = text2;
with a free(text2) at the end of the multiline section. It could be optimised to copy only if \\n is found, but it's messier and probably not worth the effort.
However, the code for this in Subtitle::InitAntialiaser (attributed to foxyshadis) contains a subtle flaw - it changes the text argument in situ, something that should never be done, since it means that the string literal in the script is effectively altered.
In this example,
function WTF(clip c, int y) {
Subtitle(c, "ABC\\nDEF", y=y, lsp=0)
}
BlankClip()
WTF(0)
WTF(20)
the first time the function is called, it works fine. However, the second time the literal has been changed, and the output is
AABC
DEF
The simplest code fix is to copy the text string before processing it in the multiline case, ie replace
psrc = (char *)text;
by
char *text2 = strdup(text);
if (!text2) goto GDIError;
psrc = text2;
with a free(text2) at the end of the multiline section. It could be optimised to copy only if \\n is found, but it's messier and probably not worth the effort.