Patchwork [2/2] virtio-9p: fix OpenBSD linker warnings

login
register
mail settings
Submitter Blue Swirl
Date May 22, 2010, 7:10 p.m.
Message ID <AANLkTinZ9cvCm70Yi7gxyxexCTnyqy9jiN5hgQgPpoVQ@mail.gmail.com>
Download mbox | patch
Permalink /patch/53281/
State New
Headers show

Comments

Blue Swirl - May 22, 2010, 7:10 p.m.
virtio-9p.o(.text+0x13c0): In function `v9fs_string_alloc_printf':
/src/qemu/hw/virtio-9p.c:270: warning: vsprintf() is often misused,
please use vsnprintf()

../libhw32/vl.o(.text+0x757c): In function `main':
/src/qemu/vl.c:3124: warning: sprintf() is often misused, please use snprintf()

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 hw/virtio-9p.c |    2 +-
 vl.c           |   14 +++++++-------
 2 files changed, 8 insertions(+), 8 deletions(-)

                     fprintf(stderr, "parse error [fsdev]: %s\n", optarg);

Patch

diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 68b0696..ee81a7a 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -267,7 +267,7 @@  static int v9fs_string_alloc_printf(char **strp,
const char *fmt, va_list ap)
 alloc_print:
     *strp = qemu_malloc((len + 1) * sizeof(**strp));

-    return vsprintf(*strp, fmt, ap);
+    return vsnprintf(*strp, len + 1, fmt, ap);
 }

 static void v9fs_string_sprintf(V9fsString *str, const char *fmt, ...)
diff --git a/vl.c b/vl.c
index d5c1e34..d66b94f 100644
--- a/vl.c
+++ b/vl.c
@@ -3121,10 +3121,10 @@  int main(int argc, char **argv, char **envp)
                     exit(1);
                 }

-                sprintf(arg_fsdev, "%s,id=%s,path=%s",
-                                qemu_opt_get(opts, "fstype"),
-                                qemu_opt_get(opts, "mount_tag"),
-                                qemu_opt_get(opts, "path"));
+                snprintf(arg_fsdev, len + 1, "%s,id=%s,path=%s",
+                         qemu_opt_get(opts, "fstype"),
+                         qemu_opt_get(opts, "mount_tag"),
+                         qemu_opt_get(opts, "path"));

                 len = strlen("virtio-9p-pci,fsdev=,mount_tag=");
                 len += 2*strlen(qemu_opt_get(opts, "mount_tag"));
@@ -3136,9 +3136,9 @@  int main(int argc, char **argv, char **envp)
                     exit(1);
                 }

-                sprintf(arg_9p, "virtio-9p-pci,fsdev=%s,mount_tag=%s",
-                                qemu_opt_get(opts, "mount_tag"),
-                                qemu_opt_get(opts, "mount_tag"));
+                snprintf(arg_9p, len + 1,
"virtio-9p-pci,fsdev=%s,mount_tag=%s",
+                         qemu_opt_get(opts, "mount_tag"),
+                         qemu_opt_get(opts, "mount_tag"));

                 if (!qemu_opts_parse(&qemu_fsdev_opts, arg_fsdev, 1)) {