qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] oslib-posix: Fix new compiler error with -Wclobbered
@ 2014-06-24 20:52 Stefan Weil
  2014-06-24 21:03 ` Paolo Bonzini
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Weil @ 2014-06-24 20:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, Paolo Bonzini, Stefan Weil

Newer versions of gcc report a warning (or an error with -Werror) when
compiler option -Wclobbered (or -Wextra) is active:

util/oslib-posix.c:372:12: error:
 variable ‘hpagesize’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Werror=clobbered]

The rewritten code fixes this warning: variable 'hpagesize' is now set and
used in a block without any call of sigsetjmp or similar functions.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
 util/oslib-posix.c |   30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index 1524ead..cdbfb2e 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -366,10 +366,9 @@ static size_t fd_getpagesize(int fd)
 
 void os_mem_prealloc(int fd, char *area, size_t memory)
 {
-    int ret, i;
+    int ret;
     struct sigaction act, oldact;
     sigset_t set, oldset;
-    size_t hpagesize = fd_getpagesize(fd);
 
     memset(&act, 0, sizeof(act));
     act.sa_handler = &sigbus_handler;
@@ -389,19 +388,22 @@ void os_mem_prealloc(int fd, char *area, size_t memory)
     if (sigsetjmp(sigjump, 1)) {
         fprintf(stderr, "os_mem_prealloc: failed to preallocate pages\n");
         exit(1);
-    }
+    } else {
+        int i;
+        size_t hpagesize = fd_getpagesize(fd);
 
-    /* MAP_POPULATE silently ignores failures */
-    memory = (memory + hpagesize - 1) & -hpagesize;
-    for (i = 0; i < (memory/hpagesize); i++) {
-        memset(area + (hpagesize*i), 0, 1);
-    }
+        /* MAP_POPULATE silently ignores failures */
+        memory = (memory + hpagesize - 1) & -hpagesize;
+        for (i = 0; i < (memory / hpagesize); i++) {
+            memset(area + (hpagesize * i), 0, 1);
+        }
 
-    ret = sigaction(SIGBUS, &oldact, NULL);
-    if (ret) {
-        perror("os_mem_prealloc: failed to reinstall signal handler");
-        exit(1);
-    }
+        ret = sigaction(SIGBUS, &oldact, NULL);
+        if (ret) {
+            perror("os_mem_prealloc: failed to reinstall signal handler");
+            exit(1);
+        }
 
-    pthread_sigmask(SIG_SETMASK, &oldset, NULL);
+        pthread_sigmask(SIG_SETMASK, &oldset, NULL);
+    }
 }
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] oslib-posix: Fix new compiler error with -Wclobbered
  2014-06-24 20:52 [Qemu-devel] [PATCH] oslib-posix: Fix new compiler error with -Wclobbered Stefan Weil
@ 2014-06-24 21:03 ` Paolo Bonzini
  2014-07-07 19:29   ` Stefan Weil
  0 siblings, 1 reply; 4+ messages in thread
From: Paolo Bonzini @ 2014-06-24 21:03 UTC (permalink / raw)
  To: Stefan Weil, qemu-devel; +Cc: qemu-trivial

Il 24/06/2014 22:52, Stefan Weil ha scritto:
> Newer versions of gcc report a warning (or an error with -Werror) when
> compiler option -Wclobbered (or -Wextra) is active:
>
> util/oslib-posix.c:372:12: error:
>  variable ‘hpagesize’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Werror=clobbered]
>
> The rewritten code fixes this warning: variable 'hpagesize' is now set and
> used in a block without any call of sigsetjmp or similar functions.
>
> Signed-off-by: Stefan Weil <sw@weilnetz.de>

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] oslib-posix: Fix new compiler error with -Wclobbered
  2014-06-24 21:03 ` Paolo Bonzini
@ 2014-07-07 19:29   ` Stefan Weil
  2014-07-08  5:38     ` Paolo Bonzini
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Weil @ 2014-07-07 19:29 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-trivial, Paolo Bonzini, qemu-devel

Am 24.06.2014 23:03, schrieb Paolo Bonzini:
> Il 24/06/2014 22:52, Stefan Weil ha scritto:
>> Newer versions of gcc report a warning (or an error with -Werror) when
>> compiler option -Wclobbered (or -Wextra) is active:
>>
>> util/oslib-posix.c:372:12: error:
>>  variable ‘hpagesize’ might be clobbered by ‘longjmp’ or ‘vfork’
>> [-Werror=clobbered]
>>
>> The rewritten code fixes this warning: variable 'hpagesize' is now set
>> and
>> used in a block without any call of sigsetjmp or similar functions.
>>
>> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> 
> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>


Ping? Maybe this patch can be committed directly as a build fix for
people like me who use compiler flag -Wextra.

Stefan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] oslib-posix: Fix new compiler error with -Wclobbered
  2014-07-07 19:29   ` Stefan Weil
@ 2014-07-08  5:38     ` Paolo Bonzini
  0 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2014-07-08  5:38 UTC (permalink / raw)
  To: Stefan Weil, Peter Maydell; +Cc: qemu-trivial, qemu-devel

Il 07/07/2014 21:29, Stefan Weil ha scritto:
> Am 24.06.2014 23:03, schrieb Paolo Bonzini:
>> Il 24/06/2014 22:52, Stefan Weil ha scritto:
>>> Newer versions of gcc report a warning (or an error with -Werror) when
>>> compiler option -Wclobbered (or -Wextra) is active:
>>>
>>> util/oslib-posix.c:372:12: error:
>>>  variable ‘hpagesize’ might be clobbered by ‘longjmp’ or ‘vfork’
>>> [-Werror=clobbered]
>>>
>>> The rewritten code fixes this warning: variable 'hpagesize' is now set
>>> and
>>> used in a block without any call of sigsetjmp or similar functions.
>>>
>>> Signed-off-by: Stefan Weil <sw@weilnetz.de>
>>
>> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
>
>
> Ping? Maybe this patch can be committed directly as a build fix for
> people like me who use compiler flag -Wextra.

Ok, I'll pick it up.

Paolo

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-07-08  5:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-24 20:52 [Qemu-devel] [PATCH] oslib-posix: Fix new compiler error with -Wclobbered Stefan Weil
2014-06-24 21:03 ` Paolo Bonzini
2014-07-07 19:29   ` Stefan Weil
2014-07-08  5:38     ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).