usb: fix unbound stack warning for inotify_watchfn
PATCH 1/1 usb: fix unbound stack warning for inotify_watchfn
Signed-off-by Peter Xu <[email protected]>
--- hw/usb/dev-mtp.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
hw/usb/dev-mtp.c +2 -3
@@ -433,12 +433,11 @@ static void inotify_watchfn(void *arg)MTPState *s = arg;ssize_t bytes;/* From the man page: atleast one event can be read */ -int len =sizeof (struct inotify_event ) +NAME_MAX +1 ;int pos; -char buf[len]; +char buf[sizeof (struct inotify_event ) +NAME_MAX +1 ];for (;;) { - bytes =read (s->inotifyfd, buf, len); + bytes =read (s->inotifyfd, buf,sizeof (buf)); pos =0 ;if (bytes <=0 ) {
Signature · 1 line
2.4.3
hw/usb/dev-mtp.c static void inotify_watchfn(void *arg) · line 440
Quoted 6 lines · Peter Xu
hw/usb/dev-mtp.c +2
-2-char buf[len]; +char buf[sizeof (struct inotify_event ) +NAME_MAX +1 ];for (;;) { - bytes =read (s->inotifyfd, buf, len); + bytes =read (s->inotifyfd, buf,sizeof (buf));
sizeof is good here, since read takes a size in bytes.
Reviewed-by Paolo Bonzini <[email protected]>