From: Stefan Weil <sw@weilnetz.de>
To: Markus Armbruster <armbru@redhat.com>
Cc: QEMU Trivial <qemu-trivial@nongnu.org>,
QEMU Developer <qemu-devel@nongnu.org>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH] trace/simple: Fix warning and wrong trace file name for MinGW
Date: Mon, 28 Sep 2015 10:26:36 +0200 [thread overview]
Message-ID: <5608F9BC.603@weilnetz.de> (raw)
In-Reply-To: <871tdjni3w.fsf@blackfin.pond.sub.org>
Am 28.09.2015 um 09:00 schrieb Markus Armbruster:
> Stefan Weil <sw@weilnetz.de> writes:
>
>> On Windows, getpid() always returns an int value, but pid_t (which is
>> expected by the format string) is either a 32 bit or a 64 bit value.
>>
>> Without a type cast (or a modified format string), the compiler prints
>> a warning when building for 64 bit Windows and the resulting trace_file_name
>> will include a wrong pid:
>>
>> trace/simple.c:332:9: warning:
>> format ‘%lld’ expects argument of type ‘long long int’,
>> but argument 2 has type ‘int’ [-Wformat=]
>>
>> Signed-off-by: Stefan Weil <sw@weilnetz.de>
>> ---
>> trace/simple.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/trace/simple.c b/trace/simple.c
>> index 11ad030..56a624c 100644
>> --- a/trace/simple.c
>> +++ b/trace/simple.c
>> @@ -329,7 +329,8 @@ bool st_set_trace_file(const char *file)
>> g_free(trace_file_name);
>>
>> if (!file) {
>> - trace_file_name = g_strdup_printf(CONFIG_TRACE_FILE, getpid());
>> + /* Type cast needed for Windows where getpid() returns an int. */
>> + trace_file_name = g_strdup_printf(CONFIG_TRACE_FILE, (pid_t)getpid());
>> } else {
>> trace_file_name = g_strdup_printf("%s", file);
>> }
> First we go to the trouble of defining a platform-dependent FMT_pid, and
> then we get to cast anyway. Meh.
>
> Can you explain why osdep.h's
>
> #define FMT_pid "%" PRId64
>
> is appropriate for Windows?
Don't blame me for any strangeness which you might find in Windows. :-)
Mingw-w64 sys/types.h defines pid_t to be either an int or an __int64.
FMT_pid must match these definitions.
But getpid returns an int, not a pid_t...
WARNING: multiple messages have this Message-ID (diff)
From: Stefan Weil <sw@weilnetz.de>
To: Markus Armbruster <armbru@redhat.com>
Cc: QEMU Trivial <qemu-trivial@nongnu.org>,
QEMU Developer <qemu-devel@nongnu.org>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] trace/simple: Fix warning and wrong trace file name for MinGW
Date: Mon, 28 Sep 2015 10:26:36 +0200 [thread overview]
Message-ID: <5608F9BC.603@weilnetz.de> (raw)
In-Reply-To: <871tdjni3w.fsf@blackfin.pond.sub.org>
Am 28.09.2015 um 09:00 schrieb Markus Armbruster:
> Stefan Weil <sw@weilnetz.de> writes:
>
>> On Windows, getpid() always returns an int value, but pid_t (which is
>> expected by the format string) is either a 32 bit or a 64 bit value.
>>
>> Without a type cast (or a modified format string), the compiler prints
>> a warning when building for 64 bit Windows and the resulting trace_file_name
>> will include a wrong pid:
>>
>> trace/simple.c:332:9: warning:
>> format ‘%lld’ expects argument of type ‘long long int’,
>> but argument 2 has type ‘int’ [-Wformat=]
>>
>> Signed-off-by: Stefan Weil <sw@weilnetz.de>
>> ---
>> trace/simple.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/trace/simple.c b/trace/simple.c
>> index 11ad030..56a624c 100644
>> --- a/trace/simple.c
>> +++ b/trace/simple.c
>> @@ -329,7 +329,8 @@ bool st_set_trace_file(const char *file)
>> g_free(trace_file_name);
>>
>> if (!file) {
>> - trace_file_name = g_strdup_printf(CONFIG_TRACE_FILE, getpid());
>> + /* Type cast needed for Windows where getpid() returns an int. */
>> + trace_file_name = g_strdup_printf(CONFIG_TRACE_FILE, (pid_t)getpid());
>> } else {
>> trace_file_name = g_strdup_printf("%s", file);
>> }
> First we go to the trouble of defining a platform-dependent FMT_pid, and
> then we get to cast anyway. Meh.
>
> Can you explain why osdep.h's
>
> #define FMT_pid "%" PRId64
>
> is appropriate for Windows?
Don't blame me for any strangeness which you might find in Windows. :-)
Mingw-w64 sys/types.h defines pid_t to be either an int or an __int64.
FMT_pid must match these definitions.
But getpid returns an int, not a pid_t...
next prev parent reply other threads:[~2015-09-28 13:22 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-25 20:12 [Qemu-trivial] [PATCH] trace/simple: Fix warning and wrong trace file name for MinGW Stefan Weil
2015-09-25 20:12 ` [Qemu-devel] " Stefan Weil
2015-09-28 7:00 ` [Qemu-trivial] " Markus Armbruster
2015-09-28 7:00 ` Markus Armbruster
2015-09-28 8:26 ` Stefan Weil [this message]
2015-09-28 8:26 ` Stefan Weil
2015-09-28 15:06 ` [Qemu-trivial] " Eric Blake
2015-09-28 15:06 ` Eric Blake
2015-09-28 15:19 ` [Qemu-trivial] " Stefan Weil
2015-09-28 15:19 ` Stefan Weil
2015-09-28 15:50 ` [Qemu-trivial] " Eric Blake
2015-09-28 15:50 ` Eric Blake
2015-09-28 19:55 ` [Qemu-trivial] " Stefan Weil
2015-09-28 19:55 ` Stefan Weil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5608F9BC.603@weilnetz.de \
--to=sw@weilnetz.de \
--cc=armbru@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.