Skip to contentSkip to conversation

kvm tools: Plug warning in virtio_p9_wstat()

PATCH In review Konstantin Khlebnikov 3 participants 3 messages Jul 10, 2011 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm tools: Plug warning in virtio_p9_wstat()

glibc declare ftruncate() with attribute warn_unused_result, so result must be "checked", otherwise we get:

virtio/9p.c:487:6: error: variable ‘res’ set but not used [-Werror=unused-but-set-variable]
or
virtio/9p.c:496:12: error: ignoring return value of ‘ftruncate’, declared with attribute warn_unused_result [-Werror=unused-result]

---
 tools/kvm/virtio/9p.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
tools/kvm/virtio/9p.c +1 -0
index d927688..4586f66 100644
@@ -495,6 +495,7 @@ static void virtio_p9_wstat(struct p9_dev *p9dev,
 
 	if (wstat.length != -1UL)
 		res = ftruncate(fid->fd, wstat.length);
+	(void)res; /* To plug the warning. FIXME what if ftruncate fails? */
 
 	if (wstat.mode != -1U)
 		chmod(fid->abs_path, wstat.mode & 0xFFFF);
#1 lore raw
Quoted 16 lines · Konstantin Khlebnikov

glibc declare ftruncate() with attribute warn_unused_result, so result must be "checked", otherwise we get:

virtio/9p.c:487:6: error: variable ‘res’ set but not used [-Werror=unused-but-set-variable]
or
virtio/9p.c:496:12: error: ignoring return value of ‘ftruncate’, declared with attribute warn_unused_result [-Werror=unused-result]

---
 tools/kvm/virtio/9p.c |    1 +

 1 files changed, 1 insertions(+), 0 deletions(-)
tools/kvm/virtio/9p.c +0 -0
index d927688..4586f66 100644

tools/kvm/virtio/9p.c static void virtio_p9_wstat(struct p9_dev *p9dev, · line 498

Quoted 4 lines
tools/kvm/virtio/9p.c +1 -0
@@ -495,6 +495,7 @@ static void virtio_p9_wstat(struct p9_dev *p9dev,
 
        if (wstat.length != -1UL)
                res = ftruncate(fid->fd, wstat.length);
+       (void)res; /* To plug the warning. FIXME what if ftruncate fails? */

There's a

make WERROR=0

to work around the warning. Sasha, Aneesh, shouldn't we propagate an error to the guest here?

Quoted 9 lines
tools/kvm/virtio/9p.c +0 -1
        if (wstat.mode != -1U)
                chmod(fid->abs_path, wstat.mode & 0xFFFF);
 
--

To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 25 lines · Pekka Enberg
Quoted 16 lines · Konstantin Khlebnikov

glibc declare ftruncate() with attribute warn_unused_result, so result must be "checked", otherwise we get:

virtio/9p.c:487:6: error: variable ‘res’ set but not used [-Werror=unused-but-set-variable]
or
virtio/9p.c:496:12: error: ignoring return value of ‘ftruncate’, declared with attribute warn_unused_result [-Werror=unused-result]

---
 tools/kvm/virtio/9p.c |    1 +

 1 files changed, 1 insertions(+), 0 deletions(-)
tools/kvm/virtio/9p.c +0 -0
index d927688..4586f66 100644

tools/kvm/virtio/9p.c static void virtio_p9_wstat(struct p9_dev *p9dev, · line 498

Quoted 4 lines
tools/kvm/virtio/9p.c +1 -0
@@ -495,6 +495,7 @@ static void virtio_p9_wstat(struct p9_dev *p9dev,
 
        if (wstat.length != -1UL)
                res = ftruncate(fid->fd, wstat.length);
+       (void)res; /* To plug the warning. FIXME what if ftruncate fails? */

There's a

Quoted 5 lines

make WERROR=0

to work around the warning. Sasha, Aneesh, shouldn't we propagate an error to the guest here?

Yes we should. We should do an RERROR message to the guest. I guess other functions in 9p.c is also missing error handling.

-aneesh