* src/convert.c (replace_attr_refresh_hack): Remove use of alloca

This commit is contained in:
Tim Rühsen 2020-02-14 15:38:53 +01:00
parent 43ad3af58d
commit 951bcac6df

View File

@ -666,11 +666,18 @@ replace_attr_refresh_hack (const char *p, int size, FILE *fp,
const char *new_text, int timeout) const char *new_text, int timeout)
{ {
/* "0; URL=..." */ /* "0; URL=..." */
char *new_with_timeout = (char *)alloca (numdigit (timeout) char new_with_timeout[1024];
+ 6 /* "; URL=" */
+ strlen (new_text) if (((unsigned) snprintf (
+ 1); new_with_timeout, sizeof (new_with_timeout),
sprintf (new_with_timeout, "%d; URL=%s", timeout, new_text); "%d; URL=%s", timeout, new_text)) >= sizeof (new_with_timeout))
{
// very unlikely fallback using heap memory
char *tmp = aprintf("%d; URL=%s", timeout, new_text);
const char *res = replace_attr (p, size, fp, tmp);
xfree (tmp);
return res;
}
return replace_attr (p, size, fp, new_with_timeout); return replace_attr (p, size, fp, new_with_timeout);
} }