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:
Wim Taymans 2021-02-02 12:09:29 +01:00
parent 41063578a5
commit 2b44f42845
13 changed files with 27 additions and 27 deletions

View file

@ -221,7 +221,7 @@ static void session_create(void *data, struct sm_object *object)
d = (struct find_data){ impl, name, SPA_ID_INVALID };
if (find_name(&d, object)) {
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",
name, val, item->key);
pw_metadata_set_property(impl->session->metadata,

View file

@ -433,7 +433,7 @@ static int restore_route(struct device *dev, struct route *r, bool save)
if ((ri = find_route_info(dev, r)) == NULL)
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);
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)
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);
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)
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);
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;
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);
if (pr.classes != NULL) {
@ -724,7 +724,7 @@ static int handle_route(struct device *dev, struct route *r)
if (r == NULL)
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);
if (restore) {

View file

@ -1798,7 +1798,7 @@ int sm_media_session_load_conf(struct sm_media_session *sess, const char *name,
if (dir == NULL)
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) {
pw_log_warn(NAME" %p: error loading config '%s': %m", sess, path);
return -errno;
@ -1833,7 +1833,7 @@ static int state_dir(struct sm_media_session *sess)
home_dir = getenv("XDG_CONFIG_HOME");
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);
else {
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");
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);
}