Received: from eggs.gnu.org ([2001:4830:134:3::10]:55948) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZgSQV-0006ph-4b for qemu-devel@nongnu.org; Mon, 28 Sep 2015 03:00:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZgSQR-0002BZ-UV for qemu-devel@nongnu.org; Mon, 28 Sep 2015 03:00:43 -0400 From: Markus Armbruster References: <1443211950-8207-1-git-send-email-sw@weilnetz.de> Date: Mon, 28 Sep 2015 09:00:35 +0200 In-Reply-To: <1443211950-8207-1-git-send-email-sw@weilnetz.de> (Stefan Weil's message of "Fri, 25 Sep 2015 22:12:30 +0200") Message-ID: <871tdjni3w.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] trace/simple: Fix warning and wrong trace file name for MinGW List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Weil Cc: QEMU Trivial , QEMU Developer , Stefan Hajnoczi Stefan Weil 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_n= ame > will include a wrong pid: > > trace/simple.c:332:9: warning: > format =E2=80=98%lld=E2=80=99 expects argument of type =E2=80=98long lon= g int=E2=80=99, > but argument 2 has type =E2=80=98int=E2=80=99 [-Wformat=3D] > > Signed-off-by: Stefan Weil > --- > 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); >=20=20 > if (!file) { > - trace_file_name =3D g_strdup_printf(CONFIG_TRACE_FILE, getpid()); > + /* Type cast needed for Windows where getpid() returns an int. */ > + trace_file_name =3D g_strdup_printf(CONFIG_TRACE_FILE, (pid_t)ge= tpid()); > } else { > trace_file_name =3D 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?