[PATCH v2] daemon: Remove use of fixed-size stack buffers.
GCC 7 complains that the fixed size buffers are not large enough (at least in theory) when using ‘-O3 -mtune=broadwell’. --- daemon/devsparts.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/daemon/devsparts.c b/daemon/devsparts.c index 584e7d8b8..82467b92f 100644 --- a/daemon/devsparts.c +++ b/daemon/devsparts.c @@ -125,13 +125,16 @@ foreach_block_device (block_dev_func_t func, bool return_md) static int add_device (const char *device, struct stringsbuf *r) { - char dev_path[256]; - snprintf (dev_path, sizeof dev_path, "/dev/%s", device); + char *dev_path; - if (add_string (r, dev_path) == -1) { + if (asprintf (&dev_path, "/dev/%s", device) == -1) { + reply_with_perror ("asprintf"); return -1; } + if (add_string_nodup (r, dev_path) == -1) + return -1; + return 0; } @@ -153,10 +156,13 @@ do_list_devices (void) static int add_partitions (const char *device, struct stringsbuf *r) { - char devdir[256]; + CLEANUP_FREE char *devdir = NULL; /* Open the device's directory under /sys/block */ - snprintf (devdir, sizeof devdir, "/sys/block/%s", device); + if (asprintf (&devdir, "/sys/block/%s", device) == -1) { + reply_with_perror ("asprintf"); + return -1; + } DIR *dir = opendir (devdir); if (!dir) { -- 2.12.0
On Thu, Apr 20, 2017 at 02:33:54PM +0200, Pino Toscano wrote:
On Wednesday, 19 April 2017 21:54:26 CEST Richard W.M. Jones wrote:
GCC 7 complains that the fixed size buffers are not large enough (at least in theory) when using ‘-O3 -mtune=broadwell’. ---
LGTM.
OK I pushed this one and also "daemon: Add an assertion to suppress a warning with GCC." which was the other simple semi-related change. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
participants (2)
-
Pino Toscano -
Richard W.M. Jones