Commit 6afadbe2 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Remove extra va_end; code factorization

parent 3a7e1af1
...@@ -161,18 +161,28 @@ static char * ...@@ -161,18 +161,28 @@ static char *
vsdp_AddAttribute (char **sdp, const char *name, const char *fmt, va_list ap) vsdp_AddAttribute (char **sdp, const char *name, const char *fmt, va_list ap)
{ {
size_t oldlen = strlen (*sdp); size_t oldlen = strlen (*sdp);
va_list aq; size_t addlen = sizeof ("a=\r\n") + strlen (name);
va_copy ( aq, ap );
size_t addlen =
sizeof ("a=:\r\n") + strlen (name) + vsnprintf (NULL, 0, fmt, ap);
char *ret = realloc (*sdp, oldlen + addlen);
if (fmt != NULL)
{
va_list aq;
va_copy (aq, ap);
addlen += 1 + vsnprintf (NULL, 0, fmt, aq);
va_end (aq);
}
char *ret = realloc (*sdp, oldlen + addlen);
if (ret == NULL) if (ret == NULL)
return NULL; return NULL;
oldlen += sprintf (ret + oldlen, "a=%s:", name); oldlen += sprintf (ret + oldlen, "a=%s", name);
oldlen += vsprintf (ret + oldlen, fmt, aq); if (fmt != NULL)
va_end (aq); {
ret[oldlen++] = ':';
oldlen += vsprintf (ret + oldlen, fmt, ap);
}
strcpy (ret + oldlen, "\r\n"); strcpy (ret + oldlen, "\r\n");
return *sdp = ret; return *sdp = ret;
} }
...@@ -181,24 +191,12 @@ vsdp_AddAttribute (char **sdp, const char *name, const char *fmt, va_list ap) ...@@ -181,24 +191,12 @@ vsdp_AddAttribute (char **sdp, const char *name, const char *fmt, va_list ap)
char *sdp_AddAttribute (char **sdp, const char *name, const char *fmt, ...) char *sdp_AddAttribute (char **sdp, const char *name, const char *fmt, ...)
{ {
char *ret; char *ret;
va_list ap;
if (fmt != NULL) va_start (ap, fmt);
{ ret = vsdp_AddAttribute (sdp, name, fmt, ap);
va_list ap; va_end (ap);
va_start (ap, fmt);
ret = vsdp_AddAttribute (sdp, name, fmt, ap);
va_end (ap);
}
else
{
size_t oldlen = strlen (*sdp);
ret = realloc (*sdp, oldlen + strlen (name) + sizeof ("a=\r\n"));
if (ret == NULL)
return NULL;
sprintf (ret + oldlen, "a=%s\r\n", name);
}
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment