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);
size_t addlen = sizeof ("a=\r\n") + strlen (name);
if (fmt != NULL)
{
va_list aq; va_list aq;
va_copy ( aq, ap );
size_t addlen =
sizeof ("a=:\r\n") + strlen (name) + vsnprintf (NULL, 0, fmt, ap);
char *ret = realloc (*sdp, oldlen + addlen);
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;
if (fmt != NULL)
{
va_list ap; va_list ap;
va_start (ap, fmt); va_start (ap, fmt);
ret = vsdp_AddAttribute (sdp, name, fmt, ap); ret = vsdp_AddAttribute (sdp, name, fmt, ap);
va_end (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