From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752919AbdKHDWh (ORCPT ); Tue, 7 Nov 2017 22:22:37 -0500 Received: from mail5.windriver.com ([192.103.53.11]:54030 "EHLO mail5.wrs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751712AbdKHDWf (ORCPT ); Tue, 7 Nov 2017 22:22:35 -0500 Subject: Re: [PATCH] selftests: memfd_test.c: fix compilation warning. To: Shuah Khan References: <1509879400-26061-1-git-send-email-Lei.Yang@windriver.com> <6a76f65a-a484-ba72-6cc5-85010666359c@osg.samsung.com> CC: , , Shuah Khan From: lei yang Message-ID: <1591d8a2-fcc4-9560-0be5-b4ddcf7825ec@windriver.com> Date: Wed, 8 Nov 2017 11:22:05 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <6a76f65a-a484-ba72-6cc5-85010666359c@osg.samsung.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [128.224.163.162] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I got the same warning even with ubuntu new distro, this patch fixed this issue. $ gcc --version gcc (Ubuntu 6.3.0-12ubuntu2) 6.3.0 20170406 Copyright (C) 2016 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ make -v GNU Make 4.1 Built for x86_64-pc-linux-gnu Copyright (C) 1988-2014 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. $ uname -a Linux pek-lyang0-u17 4.10.0-38-generic #42-Ubuntu SMP Tue Oct 10 13:24:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux --------------------- memfd_test.c: In function mfd_assert_grow_write: memfd_test.c:517:19: warning: format %d expects argument of type int, but argument 2 has type size_t {aka long unsigned int} [-Wformat=] printf("malloc(%d) failed: %m\n", mfd_def_size * 8); ^ memfd_test.c: In function mfd_fail_grow_write: memfd_test.c:537:19: warning: format %d expects argument of type int, but argument 2 has type size_t {aka long unsigned int} [-Wformat=] printf("malloc(%d) failed: %m\n", mfd_def_size * 8); Lei On 2017年11月07日 07:46, Shuah Khan wrote: > On 11/05/2017 03:56 AM, Lei Yang wrote: >> Replace '%d' by '%zu' to fix the following compilation warning. >> >> memfd_test.c:517:3: warning: format ‘%d’ expects argument of >> type ‘int’,but argument 2 has type ‘size_t’ [-Wformat=] >> printf("malloc(%d) failed: %m\n", mfd_def_size * 8); >> ^ >> memfd_test.c: In function ‘mfd_fail_grow_write’: >> memfd_test.c:537:3: warning: format ‘%d’ expects argument >> of type ‘int’,but argument 2 has type ‘size_t’ [-Wformat=] >> printf("malloc(%d) failed: %m\n", mfd_def_size * 8); >> >> Signed-off-by: Lei Yang >> --- >> tools/testing/selftests/memfd/memfd_test.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c >> index f94c6d1..95df9e6 100644 >> --- a/tools/testing/selftests/memfd/memfd_test.c >> +++ b/tools/testing/selftests/memfd/memfd_test.c >> @@ -514,7 +514,7 @@ static void mfd_assert_grow_write(int fd) >> >> buf = malloc(mfd_def_size * 8); >> if (!buf) { >> - printf("malloc(%d) failed: %m\n", mfd_def_size * 8); >> + printf("malloc(%zu) failed: %m\n", mfd_def_size * 8); >> abort(); >> } >> >> @@ -534,7 +534,7 @@ static void mfd_fail_grow_write(int fd) >> >> buf = malloc(mfd_def_size * 8); >> if (!buf) { >> - printf("malloc(%d) failed: %m\n", mfd_def_size * 8); >> + printf("malloc(%zu) failed: %m\n", mfd_def_size * 8); >> abort(); >> } >> >> > Relates to gcc version perhaps. What's your gcc version? > > thanks, > -- Shuah