zramctl: fix truncation warning
sys-utils/zramctl.c: In function ‘zram_get_sysfs’: sys-utils/zramctl.c:220:52: warning: ‘%s’ directive output may be truncated writing up to 4095 bytes into a region of size 27 [-Wformat-truncation=] snprintf(z->devname, sizeof(z->devname), "/dev/%s", name); As an additional good thing zramctl will no longer allocate 4096 bytes from stack when just 23 bytes is enough. [kzak@redhat.com: - use macro rather than hardcoded string for the path] Signed-off-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
bf99940f64
commit
8fd27bec0c
|
@ -215,9 +215,9 @@ static struct sysfs_cxt *zram_get_sysfs(struct zram *z)
|
|||
return NULL;
|
||||
if (*z->devname != '/') {
|
||||
/* canonicalize the device name according to /sys */
|
||||
char name[PATH_MAX];
|
||||
char name[sizeof(z->devname) - sizeof(_PATH_DEV)];
|
||||
if (sysfs_get_devname(&z->sysfs, name, sizeof(name)))
|
||||
snprintf(z->devname, sizeof(z->devname), "/dev/%s", name);
|
||||
snprintf(z->devname, sizeof(z->devname), _PATH_DEV "%s", name);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue