summaryrefslogtreecommitdiffstats
path: root/disk-utils/cfdisk.c
diff options
context:
space:
mode:
authorSami Kerola2017-02-11 20:01:08 +0100
committerKarel Zak2017-02-20 12:58:12 +0100
commite948f4b616d02576032e8e9960d1241a77fe4e8d (patch)
tree63fedd6c970e7f6e8462d4075cdbb2eaedb59b9c /disk-utils/cfdisk.c
parenttests: make sfdisk wipe partition optional (diff)
downloadkernel-qcow2-util-linux-e948f4b616d02576032e8e9960d1241a77fe4e8d.tar.gz
kernel-qcow2-util-linux-e948f4b616d02576032e8e9960d1241a77fe4e8d.tar.xz
kernel-qcow2-util-linux-e948f4b616d02576032e8e9960d1241a77fe4e8d.zip
cfdisk: avoid use of VLA in combination with sizeof() [smatch scan]
disk-utils/cfdisk.c:1066:29: error: cannot size expression One should use sizeof() only when variable size can be known at time of compilation. That is not the case with variable length arrays. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'disk-utils/cfdisk.c')
-rw-r--r--disk-utils/cfdisk.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c
index e4470e951..19b62f24b 100644
--- a/disk-utils/cfdisk.c
+++ b/disk-utils/cfdisk.c
@@ -1049,9 +1049,10 @@ static void ui_draw_menuitem(struct cfdisk *cf,
struct cfdisk_menuitem *d,
size_t idx)
{
- char buf[80 * MB_CUR_MAX], *ptr = buf;
+ char *buf, *ptr;
const char *name;
size_t width;
+ const size_t buf_sz = 80 * MB_CUR_MAX;
int ln, cl, vert = cf->menu->vertical;
if (!menuitem_on_page(cf, idx))
@@ -1059,6 +1060,7 @@ static void ui_draw_menuitem(struct cfdisk *cf,
ln = menuitem_get_line(cf, idx);
cl = menuitem_get_column(cf, idx);
+ ptr = buf = xmalloc(buf_sz);
/* string width */
if (vert) {
width = cf->menu->width + MENU_V_SPADDING;
@@ -1068,7 +1070,7 @@ static void ui_draw_menuitem(struct cfdisk *cf,
width = MENU_H_SPADDING + cf->menu->width + MENU_H_SPADDING;
name = _(d->name);
- mbsalign(name, ptr, sizeof(buf), &width,
+ mbsalign(name, ptr, buf_sz, &width,
vert ? MBS_ALIGN_LEFT : MBS_ALIGN_CENTER,
0);
@@ -1087,6 +1089,7 @@ static void ui_draw_menuitem(struct cfdisk *cf,
mvprintw(ln, cl, "%s", buf);
else
mvprintw(ln, cl, "%s%s%s", MENU_H_PRESTR, buf, MENU_H_POSTSTR);
+ free(buf);
if (cf->menu->idx == idx) {
standend();