mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
pass the complete buffer size to snprintf
There is no reason to pass size-1, snprintf will always put a \0 at the end.
This commit is contained in:
parent
41063578a5
commit
2b44f42845
13 changed files with 27 additions and 27 deletions
|
|
@ -636,7 +636,7 @@ const char *
|
||||||
jack_get_version_string(void)
|
jack_get_version_string(void)
|
||||||
{
|
{
|
||||||
static char name[1024];
|
static char name[1024];
|
||||||
snprintf(name, sizeof(name)-1, "3.0.0.0 (using PipeWire %s)", pw_get_library_version());
|
snprintf(name, sizeof(name), "3.0.0.0 (using PipeWire %s)", pw_get_library_version());
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -184,7 +184,7 @@ static int emit_node(struct impl *this, struct acp_device *dev)
|
||||||
items[2] = SPA_DICT_ITEM_INIT(SPA_KEY_API_ALSA_PCM_CARD, card_id);
|
items[2] = SPA_DICT_ITEM_INIT(SPA_KEY_API_ALSA_PCM_CARD, card_id);
|
||||||
items[3] = SPA_DICT_ITEM_INIT(SPA_KEY_API_ALSA_PCM_STREAM, stream);
|
items[3] = SPA_DICT_ITEM_INIT(SPA_KEY_API_ALSA_PCM_STREAM, stream);
|
||||||
|
|
||||||
snprintf(channels, sizeof(channels)-1, "%d", dev->format.channels);
|
snprintf(channels, sizeof(channels), "%d", dev->format.channels);
|
||||||
items[4] = SPA_DICT_ITEM_INIT(SPA_KEY_AUDIO_CHANNELS, channels);
|
items[4] = SPA_DICT_ITEM_INIT(SPA_KEY_AUDIO_CHANNELS, channels);
|
||||||
|
|
||||||
p = positions;
|
p = positions;
|
||||||
|
|
@ -928,7 +928,7 @@ impl_init(const struct spa_handle_factory *factory,
|
||||||
|
|
||||||
if (info) {
|
if (info) {
|
||||||
if ((str = spa_dict_lookup(info, SPA_KEY_API_ALSA_PATH)) != NULL)
|
if ((str = spa_dict_lookup(info, SPA_KEY_API_ALSA_PATH)) != NULL)
|
||||||
snprintf(this->props.device, sizeof(this->props.device)-1, "%s", str);
|
snprintf(this->props.device, sizeof(this->props.device), "%s", str);
|
||||||
if ((str = spa_dict_lookup(info, "api.acp.auto-port")) != NULL)
|
if ((str = spa_dict_lookup(info, "api.acp.auto-port")) != NULL)
|
||||||
this->props.auto_port = strcmp(str, "true") == 0 || atoi(str) != 0;
|
this->props.auto_port = strcmp(str, "true") == 0 || atoi(str) != 0;
|
||||||
if ((str = spa_dict_lookup(info, "api.acp.auto-profile")) != NULL)
|
if ((str = spa_dict_lookup(info, "api.acp.auto-profile")) != NULL)
|
||||||
|
|
|
||||||
|
|
@ -376,7 +376,7 @@ static bool check_access(struct impl *this, struct device *device)
|
||||||
{
|
{
|
||||||
char path[128];
|
char path[128];
|
||||||
|
|
||||||
snprintf(path, sizeof(path)-1, "/dev/snd/controlC%u", device->id);
|
snprintf(path, sizeof(path), "/dev/snd/controlC%u", device->id);
|
||||||
device->accessible = access(path, R_OK|W_OK) >= 0;
|
device->accessible = access(path, R_OK|W_OK) >= 0;
|
||||||
spa_log_debug(this->log, "%s accessible:%u", path, device->accessible);
|
spa_log_debug(this->log, "%s accessible:%u", path, device->accessible);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -323,7 +323,7 @@ static bool check_access(struct impl *this, struct device *device)
|
||||||
{
|
{
|
||||||
char path[128];
|
char path[128];
|
||||||
|
|
||||||
snprintf(path, sizeof(path)-1, "/dev/video%u", device->id);
|
snprintf(path, sizeof(path), "/dev/video%u", device->id);
|
||||||
device->accessible = access(path, R_OK|W_OK) >= 0;
|
device->accessible = access(path, R_OK|W_OK) >= 0;
|
||||||
spa_log_debug(this->log, "%s accessible:%u", path, device->accessible);
|
spa_log_debug(this->log, "%s accessible:%u", path, device->accessible);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -221,7 +221,7 @@ static void session_create(void *data, struct sm_object *object)
|
||||||
d = (struct find_data){ impl, name, SPA_ID_INVALID };
|
d = (struct find_data){ impl, name, SPA_ID_INVALID };
|
||||||
if (find_name(&d, object)) {
|
if (find_name(&d, object)) {
|
||||||
char val[16];
|
char val[16];
|
||||||
snprintf(val, sizeof(val)-1, "%u", d.id);
|
snprintf(val, sizeof(val), "%u", d.id);
|
||||||
pw_log_info("found %s with id:%s restore as %s",
|
pw_log_info("found %s with id:%s restore as %s",
|
||||||
name, val, item->key);
|
name, val, item->key);
|
||||||
pw_metadata_set_property(impl->session->metadata,
|
pw_metadata_set_property(impl->session->metadata,
|
||||||
|
|
|
||||||
|
|
@ -433,7 +433,7 @@ static int restore_route(struct device *dev, struct route *r, bool save)
|
||||||
if ((ri = find_route_info(dev, r)) == NULL)
|
if ((ri = find_route_info(dev, r)) == NULL)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
snprintf(key, sizeof(key)-1, PREFIX"%s:%s:%s", dev->name,
|
snprintf(key, sizeof(key), PREFIX"%s:%s:%s", dev->name,
|
||||||
r->direction == SPA_DIRECTION_INPUT ? "input" : "output", r->name);
|
r->direction == SPA_DIRECTION_INPUT ? "input" : "output", r->name);
|
||||||
|
|
||||||
val = pw_properties_get(impl->to_restore, key);
|
val = pw_properties_get(impl->to_restore, key);
|
||||||
|
|
@ -458,7 +458,7 @@ static int save_route(struct device *dev, struct route *r)
|
||||||
if (r->props == NULL)
|
if (r->props == NULL)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
snprintf(key, sizeof(key)-1, PREFIX"%s:%s:%s", dev->name,
|
snprintf(key, sizeof(key), PREFIX"%s:%s:%s", dev->name,
|
||||||
r->direction == SPA_DIRECTION_INPUT ? "input" : "output", r->name);
|
r->direction == SPA_DIRECTION_INPUT ? "input" : "output", r->name);
|
||||||
|
|
||||||
val = serialize_props(dev, r->props);
|
val = serialize_props(dev, r->props);
|
||||||
|
|
@ -499,7 +499,7 @@ static int save_profile(struct device *dev)
|
||||||
if (pw_array_get_len(&dev->route_info, struct route_info) == 0)
|
if (pw_array_get_len(&dev->route_info, struct route_info) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
snprintf(key, sizeof(key)-1, PREFIX"%s:profile:%s", dev->name, dev->profile_name);
|
snprintf(key, sizeof(key), PREFIX"%s:profile:%s", dev->name, dev->profile_name);
|
||||||
|
|
||||||
val = serialize_routes(dev);
|
val = serialize_routes(dev);
|
||||||
if (pw_properties_set(impl->to_restore, key, val)) {
|
if (pw_properties_set(impl->to_restore, key, val)) {
|
||||||
|
|
@ -626,7 +626,7 @@ static int handle_profile(struct device *dev)
|
||||||
dev->active_profile = pr.index;
|
dev->active_profile = pr.index;
|
||||||
snprintf(dev->profile_name, sizeof(dev->profile_name), "%s", pr.name);
|
snprintf(dev->profile_name, sizeof(dev->profile_name), "%s", pr.name);
|
||||||
|
|
||||||
snprintf(key, sizeof(key)-1, PREFIX"%s:profile:%s", dev->name, dev->profile_name);
|
snprintf(key, sizeof(key), PREFIX"%s:profile:%s", dev->name, dev->profile_name);
|
||||||
json = pw_properties_get(impl->to_restore, key);
|
json = pw_properties_get(impl->to_restore, key);
|
||||||
|
|
||||||
if (pr.classes != NULL) {
|
if (pr.classes != NULL) {
|
||||||
|
|
@ -724,7 +724,7 @@ static int handle_route(struct device *dev, struct route *r)
|
||||||
if (r == NULL)
|
if (r == NULL)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
snprintf(key, sizeof(key)-1, PREFIX"%s:%s:%s", dev->name,
|
snprintf(key, sizeof(key), PREFIX"%s:%s:%s", dev->name,
|
||||||
r->direction == SPA_DIRECTION_INPUT ? "input" : "output", r->name);
|
r->direction == SPA_DIRECTION_INPUT ? "input" : "output", r->name);
|
||||||
|
|
||||||
if (restore) {
|
if (restore) {
|
||||||
|
|
|
||||||
|
|
@ -1798,7 +1798,7 @@ int sm_media_session_load_conf(struct sm_media_session *sess, const char *name,
|
||||||
if (dir == NULL)
|
if (dir == NULL)
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
|
||||||
snprintf(path, sizeof(path)-1, "%s/media-session.d/%s", dir, name);
|
snprintf(path, sizeof(path), "%s/media-session.d/%s", dir, name);
|
||||||
if ((fd = open(path, O_CLOEXEC | O_RDONLY)) < 0) {
|
if ((fd = open(path, O_CLOEXEC | O_RDONLY)) < 0) {
|
||||||
pw_log_warn(NAME" %p: error loading config '%s': %m", sess, path);
|
pw_log_warn(NAME" %p: error loading config '%s': %m", sess, path);
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
@ -1833,7 +1833,7 @@ static int state_dir(struct sm_media_session *sess)
|
||||||
|
|
||||||
home_dir = getenv("XDG_CONFIG_HOME");
|
home_dir = getenv("XDG_CONFIG_HOME");
|
||||||
if (home_dir != NULL)
|
if (home_dir != NULL)
|
||||||
snprintf(impl->state_dir, sizeof(impl->state_dir)-1,
|
snprintf(impl->state_dir, sizeof(impl->state_dir),
|
||||||
"%s/pipewire-media-session/", home_dir);
|
"%s/pipewire-media-session/", home_dir);
|
||||||
else {
|
else {
|
||||||
home_dir = getenv("HOME");
|
home_dir = getenv("HOME");
|
||||||
|
|
@ -1849,7 +1849,7 @@ static int state_dir(struct sm_media_session *sess)
|
||||||
pw_log_error("Can't determine home directory");
|
pw_log_error("Can't determine home directory");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
snprintf(impl->state_dir, sizeof(impl->state_dir)-1,
|
snprintf(impl->state_dir, sizeof(impl->state_dir),
|
||||||
"%s/.config/pipewire-media-session/", home_dir);
|
"%s/.config/pipewire-media-session/", home_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ static void node_port_init(void *data, struct pw_impl_port *port)
|
||||||
|
|
||||||
if ((str = pw_properties_get(old, PW_KEY_AUDIO_CHANNEL)) == NULL ||
|
if ((str = pw_properties_get(old, PW_KEY_AUDIO_CHANNEL)) == NULL ||
|
||||||
strcmp(str, "UNK") == 0) {
|
strcmp(str, "UNK") == 0) {
|
||||||
snprintf(position, sizeof(position)-1, "%d", pw_impl_port_get_id(port));
|
snprintf(position, sizeof(position), "%d", pw_impl_port_get_id(port));
|
||||||
str = position;
|
str = position;
|
||||||
}
|
}
|
||||||
if (direction == n->direction) {
|
if (direction == n->direction) {
|
||||||
|
|
|
||||||
|
|
@ -691,7 +691,7 @@ int pw_manager_set_metadata(struct pw_manager *manager,
|
||||||
|
|
||||||
if (type != NULL) {
|
if (type != NULL) {
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
vsnprintf(buf, sizeof(buf)-1, format, args);
|
vsnprintf(buf, sizeof(buf), format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
value = buf;
|
value = buf;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1109,11 +1109,11 @@ static int reply_create_playback_stream(struct stream *stream)
|
||||||
lat.denom = stream->ss.rate;
|
lat.denom = stream->ss.rate;
|
||||||
lat_usec = lat.num * SPA_USEC_PER_SEC / lat.denom;
|
lat_usec = lat.num * SPA_USEC_PER_SEC / lat.denom;
|
||||||
|
|
||||||
snprintf(latency, sizeof(latency)-1, "%u/%u", lat.num, lat.denom);
|
snprintf(latency, sizeof(latency), "%u/%u", lat.num, lat.denom);
|
||||||
snprintf(attr_maxlength, sizeof(attr_maxlength)-1, "%u", stream->attr.maxlength);
|
snprintf(attr_maxlength, sizeof(attr_maxlength), "%u", stream->attr.maxlength);
|
||||||
snprintf(attr_tlength, sizeof(attr_tlength)-1, "%u", stream->attr.tlength);
|
snprintf(attr_tlength, sizeof(attr_tlength), "%u", stream->attr.tlength);
|
||||||
snprintf(attr_prebuf, sizeof(attr_prebuf)-1, "%u", stream->attr.prebuf);
|
snprintf(attr_prebuf, sizeof(attr_prebuf), "%u", stream->attr.prebuf);
|
||||||
snprintf(attr_minreq, sizeof(attr_minreq)-1, "%u", stream->attr.minreq);
|
snprintf(attr_minreq, sizeof(attr_minreq), "%u", stream->attr.minreq);
|
||||||
|
|
||||||
items[0] = SPA_DICT_ITEM_INIT(PW_KEY_NODE_LATENCY, latency);
|
items[0] = SPA_DICT_ITEM_INIT(PW_KEY_NODE_LATENCY, latency);
|
||||||
items[1] = SPA_DICT_ITEM_INIT("pulse.attr.maxlength", attr_maxlength);
|
items[1] = SPA_DICT_ITEM_INIT("pulse.attr.maxlength", attr_maxlength);
|
||||||
|
|
@ -1241,7 +1241,7 @@ static int reply_create_record_stream(struct stream *stream)
|
||||||
lat.denom = stream->ss.rate;
|
lat.denom = stream->ss.rate;
|
||||||
lat_usec = lat.num * SPA_USEC_PER_SEC / lat.denom;
|
lat_usec = lat.num * SPA_USEC_PER_SEC / lat.denom;
|
||||||
|
|
||||||
snprintf(latency, sizeof(latency)-1, "%u/%u", lat.num, lat.denom);
|
snprintf(latency, sizeof(latency), "%u/%u", lat.num, lat.denom);
|
||||||
|
|
||||||
items[0] = SPA_DICT_ITEM_INIT(PW_KEY_NODE_LATENCY, latency);
|
items[0] = SPA_DICT_ITEM_INIT(PW_KEY_NODE_LATENCY, latency);
|
||||||
items[1] = SPA_DICT_ITEM_INIT("pulse.attr.maxlength", attr_maxlength);
|
items[1] = SPA_DICT_ITEM_INIT("pulse.attr.maxlength", attr_maxlength);
|
||||||
|
|
@ -3293,7 +3293,7 @@ static int do_get_server_info(struct client *client, uint32_t command, uint32_t
|
||||||
cookie = 0;
|
cookie = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(name, sizeof(name)-1, "PulseAudio (on PipeWire %s)", pw_get_library_version());
|
snprintf(name, sizeof(name), "PulseAudio (on PipeWire %s)", pw_get_library_version());
|
||||||
|
|
||||||
reply = reply_new(client, tag);
|
reply = reply_new(client, tag);
|
||||||
message_put(reply,
|
message_put(reply,
|
||||||
|
|
@ -5302,7 +5302,7 @@ get_runtime_dir(char *buf, size_t buflen, const char *dir)
|
||||||
if (getpwuid_r(getuid(), &pwd, buffer, sizeof(buffer), &result) == 0)
|
if (getpwuid_r(getuid(), &pwd, buffer, sizeof(buffer), &result) == 0)
|
||||||
runtime_dir = result ? result->pw_dir : NULL;
|
runtime_dir = result ? result->pw_dir : NULL;
|
||||||
}
|
}
|
||||||
size = snprintf(buf, buflen-1, "%s/%s", runtime_dir, dir) + 1;
|
size = snprintf(buf, buflen, "%s/%s", runtime_dir, dir) + 1;
|
||||||
if (size > (int) buflen) {
|
if (size > (int) buflen) {
|
||||||
pw_log_error(NAME": path %s/%s too long", runtime_dir, dir);
|
pw_log_error(NAME": path %s/%s too long", runtime_dir, dir);
|
||||||
return -ENAMETOOLONG;
|
return -ENAMETOOLONG;
|
||||||
|
|
|
||||||
|
|
@ -540,7 +540,7 @@ const char *pw_get_prgname(void)
|
||||||
return prgname;
|
return prgname;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
snprintf(prgname, sizeof(prgname)-1, "pid-%d", getpid());
|
snprintf(prgname, sizeof(prgname), "pid-%d", getpid());
|
||||||
return prgname;
|
return prgname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -306,7 +306,7 @@ static void put_pod_value(struct data *d, const char *key, const struct spa_type
|
||||||
uint32_t id = *(uint32_t*)body;
|
uint32_t id = *(uint32_t*)body;
|
||||||
str = spa_debug_type_find_short_name(info, *(uint32_t*)body);
|
str = spa_debug_type_find_short_name(info, *(uint32_t*)body);
|
||||||
if (str == NULL) {
|
if (str == NULL) {
|
||||||
snprintf(fallback, sizeof(fallback)-1, "id-%08x", id);
|
snprintf(fallback, sizeof(fallback), "id-%08x", id);
|
||||||
str = fallback;
|
str = fallback;
|
||||||
}
|
}
|
||||||
put_value(d, NULL, str);
|
put_value(d, NULL, str);
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ static struct node *add_node(struct data *d, uint32_t id, const char *name)
|
||||||
if (name)
|
if (name)
|
||||||
strncpy(n->name, name, MAX_NAME-1);
|
strncpy(n->name, name, MAX_NAME-1);
|
||||||
else
|
else
|
||||||
snprintf(n->name, sizeof(n->name)-1, "%u", id);
|
snprintf(n->name, sizeof(n->name), "%u", id);
|
||||||
n->id = id;
|
n->id = id;
|
||||||
n->driver = n;
|
n->driver = n;
|
||||||
spa_list_append(&d->node_list, &n->link);
|
spa_list_append(&d->node_list, &n->link);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue