From: Tom Rini Date: Thu, 28 Aug 2014 08:42:33 -0400 Subject: [U-Boot] [PATCH] common: fix compiler warning on wrong printf format In-Reply-To: References: <1409061773-14375-1-git-send-email-abrodkin@synopsys.com> Message-ID: <20140828124233.GW19374@bill-the-cat> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Wed, Aug 27, 2014 at 10:27:19AM +1200, Chris Packham wrote: > On Wed, Aug 27, 2014 at 2:02 AM, Alexey Brodkin > wrote: > > bounce_buffer->len_aligned is of type "size_t", but on some arches/compilers > > "size_t" might be an alias to whether "int", "long" or their "signed/unsigned" > > flavors. > > > > So to make compiler happy we explicitly cast to "int" which is expected in > > printf for "%d" format. > > > > this fixes following warning: > > --->--- > > common/bouncebuf.c: In function ?addr_aligned?: > > common/bouncebuf.c:26:3: warning: format ?%d? expects argument of type ?int?, but argument 2 has type ?size_t? [-Wformat=] > > debug("Unaligned buffer length %d\n", /*(int)*/state->len); > > ^ > > --->--- > > > > Signed-off-by: Alexey Brodkin > > Cc: Vasili Galka > > Cc: Tom Rini > > --- > > common/bouncebuf.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/common/bouncebuf.c b/common/bouncebuf.c > > index 9eece6d..0828d4b 100644 > > --- a/common/bouncebuf.c > > +++ b/common/bouncebuf.c > > @@ -23,7 +23,7 @@ static int addr_aligned(struct bounce_buffer *state) > > > > /* Check if length is aligned */ > > if (state->len != state->len_aligned) { > > - debug("Unaligned buffer length %d\n", state->len); > > + debug("Unaligned buffer length %d\n", (int)state->len); > > Another way of fixing this would be to use %zu or %zd instead of %d. > Although that is a C99 addition so I'm not sure how much people care > about really old compilers. And %zd has other usages in the codebase so please use that, thanks. -- Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: