mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-01 22:58:50 -04:00
protocol-pulse: fix two -Wformat-nonliteral warnings
For the stream group, we break into the three components we write out and print those. For the IPv6 address printing inside [], we can make this a condition on the printf statement.
This commit is contained in:
parent
e55a5441b8
commit
8bb0e340c7
2 changed files with 14 additions and 11 deletions
|
|
@ -515,7 +515,7 @@ static void write_cvolume(struct message *m, struct volume *vol)
|
|||
static void add_stream_group(struct message *m, struct spa_dict *dict, const char *key,
|
||||
const char *media_class, const char *media_role)
|
||||
{
|
||||
const char *str, *fmt, *prefix;
|
||||
const char *str, *id, *prefix;
|
||||
char *b;
|
||||
int l;
|
||||
|
||||
|
|
@ -529,20 +529,20 @@ static void add_stream_group(struct message *m, struct spa_dict *dict, const cha
|
|||
return;
|
||||
|
||||
if ((str = media_role) != NULL)
|
||||
fmt = "%s-by-media-role:%s";
|
||||
id = "media-role";
|
||||
else if ((str = spa_dict_lookup(dict, PW_KEY_APP_ID)) != NULL)
|
||||
fmt = "%s-by-application-id:%s";
|
||||
id = "application-id";
|
||||
else if ((str = spa_dict_lookup(dict, PW_KEY_APP_NAME)) != NULL)
|
||||
fmt = "%s-by-application-name:%s";
|
||||
id = "application-name";
|
||||
else if ((str = spa_dict_lookup(dict, PW_KEY_MEDIA_NAME)) != NULL)
|
||||
fmt = "%s-by-media-name:%s";
|
||||
id = "media-name";
|
||||
else
|
||||
return;
|
||||
|
||||
write_string(m, key);
|
||||
l = strlen(fmt) + strlen(prefix) + strlen(str) - 3;
|
||||
l = strlen(prefix) + strlen(id) + strlen(str) + 6; /* "-by-" , ":" and \0 */
|
||||
b = alloca(l);
|
||||
snprintf(b, l, fmt, prefix, str);
|
||||
snprintf(b, l, "%s-by-%s:%s", prefix, id, str);
|
||||
write_u32(m, l);
|
||||
write_arbitrary(m, b, l);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -712,17 +712,16 @@ static int format_ip_address(const struct sockaddr_storage *addr, char *buffer,
|
|||
{
|
||||
char ip[INET6_ADDRSTRLEN];
|
||||
const void *src;
|
||||
const char *fmt;
|
||||
bool is_ipv6 = false;
|
||||
int port;
|
||||
|
||||
switch (addr->ss_family) {
|
||||
case AF_INET:
|
||||
fmt = "%s:%d";
|
||||
src = &((struct sockaddr_in *) addr)->sin_addr.s_addr;
|
||||
port = ntohs(((struct sockaddr_in *) addr)->sin_port);
|
||||
break;
|
||||
case AF_INET6:
|
||||
fmt = "[%s]:%d";
|
||||
is_ipv6 = true;
|
||||
src = &((struct sockaddr_in6 *) addr)->sin6_addr.s6_addr;
|
||||
port = ntohs(((struct sockaddr_in6 *) addr)->sin6_port);
|
||||
break;
|
||||
|
|
@ -733,7 +732,11 @@ static int format_ip_address(const struct sockaddr_storage *addr, char *buffer,
|
|||
if (inet_ntop(addr->ss_family, src, ip, sizeof(ip)) == NULL)
|
||||
return -errno;
|
||||
|
||||
return snprintf(buffer, buflen, fmt, ip, port);
|
||||
return snprintf(buffer, buflen, "%s%s%s:%d",
|
||||
is_ipv6 ? "[" : "",
|
||||
ip,
|
||||
is_ipv6 ? "]" : "",
|
||||
port);
|
||||
}
|
||||
|
||||
static int get_ip_address_length(const struct sockaddr_storage *addr)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue