All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andre Przywara <andre.przywara-5wv7dgnIgG8@public.gmane.org>
To: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
	David Gibson
	<david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
Cc: Devicetree Compiler
	<devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: [PATCH 04/11] fdtget: Fix signedness comparisons warnings
Date: Mon, 12 Oct 2020 17:19:41 +0100	[thread overview]
Message-ID: <20201012161948.23994-5-andre.przywara@arm.com> (raw)
In-Reply-To: <20201012161948.23994-1-andre.przywara-5wv7dgnIgG8@public.gmane.org>

With -Wsign-compare, compilers warn about a mismatching signedness in
the different legs of the conditional operator, in fdtget.c.

In the questionable expression, we are constructing a 16-bit value out of
two unsigned 8-bit values, however are relying on the compiler's
automatic expansion of the uint8_t to a larger type, to survive the left
shift. This larger type happens to be an "int", so this part of the
expression becomes signed.

Fix this by explicitly blow up the uint8_t to a larger *unsigned* type,
before doing the left shift. That keeps all parts of the conditional
operator "unsigned", and prevents the original warning.

This fixes "make fdtget", when compiled with -Wsign-compare.

Signed-off-by: Andre Przywara <andre.przywara-5wv7dgnIgG8@public.gmane.org>
---
 fdtget.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fdtget.c b/fdtget.c
index 777582e..c5685d9 100644
--- a/fdtget.c
+++ b/fdtget.c
@@ -62,8 +62,8 @@ static int show_cell_list(struct display_info *disp, const char *data, int len,
 	for (i = 0; i < len; i += size, p += size) {
 		if (i)
 			printf(" ");
-		value = size == 4 ? fdt32_ld((const fdt32_t *)p) :
-			size == 2 ? (*p << 8) | p[1] : *p;
+		value = (size == 4) ? fdt32_ld((const fdt32_t *)p) :
+			((size == 2) ? ((unsigned)(*p) << 8) | p[1] : *p);
 		printf(fmt, value);
 	}
 
-- 
2.17.5


  parent reply	other threads:[~2020-10-12 16:19 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-12 16:19 [PATCH 00/11] dtc: Fix signed/unsigned comparison warnings Andre Przywara
     [not found] ` <20201012161948.23994-1-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-10-12 16:19   ` [PATCH 01/11] tests: Fix signedness comparisons warnings Andre Przywara
     [not found]     ` <20201012161948.23994-2-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-10-13  5:09       ` David Gibson
     [not found]         ` <20201013050927.GU71119-l+x2Y8Cxqc4e6aEkudXLsA@public.gmane.org>
2021-06-11 17:11           ` Andre Przywara
     [not found]             ` <20210611181134.3ba96b43-KTS7eRBhINUXU02nzanrWNbf9cGiqdzd@public.gmane.org>
2021-06-15  2:58               ` David Gibson
2020-10-12 16:19   ` [PATCH 02/11] convert-dtsv0: Fix signedness comparisons warning Andre Przywara
     [not found]     ` <20201012161948.23994-3-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-10-13  4:48       ` David Gibson
2020-10-12 16:19   ` [PATCH 03/11] fdtdump: Fix signedness comparisons warnings Andre Przywara
     [not found]     ` <20201012161948.23994-4-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-10-13  4:51       ` David Gibson
2020-10-12 16:19   ` Andre Przywara [this message]
     [not found]     ` <20201012161948.23994-5-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-10-13  4:54       ` [PATCH 04/11] fdtget: " David Gibson
2020-10-12 16:19   ` [PATCH 05/11] dtc: Wrap phandle validity check Andre Przywara
     [not found]     ` <20201012161948.23994-6-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-10-13  4:55       ` David Gibson
2020-10-12 16:19   ` [PATCH 06/11] dtc: Fix signedness comparisons warnings: change types Andre Przywara
     [not found]     ` <20201012161948.23994-7-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-10-13  4:57       ` David Gibson
2020-10-12 16:19   ` [PATCH 07/11] dtc: Fix signedness comparisons warnings: reservednum Andre Przywara
     [not found]     ` <20201012161948.23994-8-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-10-13  4:58       ` David Gibson
2020-10-12 16:19   ` [PATCH 08/11] dtc: Fix signedness comparisons warnings: Wrap (-1) Andre Przywara
     [not found]     ` <20201012161948.23994-9-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-10-13  4:59       ` David Gibson
2020-10-12 16:19   ` [PATCH 09/11] dtc: Fix signedness comparisons warnings: pointer diff Andre Przywara
     [not found]     ` <20201012161948.23994-10-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-10-13  5:01       ` David Gibson
2020-10-12 16:19   ` [PATCH 10/11] checks: Fix signedness comparisons warnings Andre Przywara
     [not found]     ` <20201012161948.23994-11-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-10-13  5:02       ` David Gibson
2020-10-12 16:19   ` [PATCH 11/11] Makefile: add -Wsign-compare to warning options Andre Przywara

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=20201012161948.23994-5-andre.przywara@arm.com \
    --to=andre.przywara-5wv7dgnigg8@public.gmane.org \
    --cc=david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org \
    --cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
    /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.