Pino Toscano
2018-Apr-30 11:07 UTC
[Libguestfs] [PATCH 4/4] daemon: simplify string allocation
When creating an helper string for do_aug_match(), use a simpler
asprintf() with manual free(), since the code block is small enough.
This slightly helps static code analyzers.
---
daemon/augeas.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/daemon/augeas.c b/daemon/augeas.c
index bd54c4849..453251337 100644
--- a/daemon/augeas.c
+++ b/daemon/augeas.c
@@ -420,17 +420,15 @@ do_aug_ls (const char *path)
if (STREQ (path, "/"))
matches = do_aug_match ("/*");
else {
- CLEANUP_FREE char *buf = NULL;
+ char *buf = NULL;
- len += 3; /* / * + terminating \0 */
- buf = malloc (len);
- if (buf == NULL) {
- reply_with_perror ("malloc");
+ if (asprintf (&buf, "%s/*", path) == -1) {
+ reply_with_perror ("asprintf");
return NULL;
}
- snprintf (buf, len, "%s/*", path);
matches = do_aug_match (buf);
+ free (buf);
}
if (matches == NULL)
--
2.14.3
Richard W.M. Jones
2018-Apr-30 11:20 UTC
Re: [Libguestfs] [PATCH 4/4] daemon: simplify string allocation
ACK series. Were these found by Coverity? If so then we usually mention that in the commit message. Thanks, 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
Richard W.M. Jones
2018-May-01 16:29 UTC
Re: [Libguestfs] [PATCH 4/4] daemon: simplify string allocation
On Mon, Apr 30, 2018 at 12:20:51PM +0100, Richard W.M. Jones wrote:> > ACK series.I pushed these in order to get them into the next 1.39.4 release. Thanks, 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
Maybe Matching Threads
- [PATCH v7 13/13] daemon: Link guestfsd with libutils.
- [PATCH] Clarify the error message when unavailable functions are called (RHBZ#679737).
- [PATCH 09/27] daemon: Reimplement ‘mount’, ‘mount_ro’, ‘mount_options’, ‘mount_vfs’ APIs in OCaml.
- [PATCH] renamed daemon/tsk.c to daemon/sleuthkit.c
- [PATCH] daemon: Remove use of fixed-size stack buffers.