From: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
To: Andre Przywara <andre.przywara-5wv7dgnIgG8@public.gmane.org>
Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Subject: Re: [PATCH v2 6/8] dtc: Fix signedness comparisons warnings: pointer diff
Date: Tue, 15 Jun 2021 12:49:31 +1000 [thread overview]
Message-ID: <YMgVO6w1oXki9b0G@yekko> (raw)
In-Reply-To: <20210611171040.25524-7-andre.przywara-5wv7dgnIgG8@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 1437 bytes --]
On Fri, Jun 11, 2021 at 06:10:38PM +0100, Andre Przywara wrote:
> With -Wsign-compare, compilers warn about a mismatching signedness
> in comparisons in the function get_node_by_path().
>
> Taking the difference between two pointers results in a signed ptrdiff_t
> type, which mismatches the unsigned type returned by strlen().
> Since "p" has been returned by a call to strchr() with "path" as its
> argument, we know for sure that it's bigger than "path", so the
> difference must be positive. So a cast to an unsigned type is valid.
>
> Signed-off-by: Andre Przywara <andre.przywara-5wv7dgnIgG8@public.gmane.org>
Applied, thanks.
> ---
> livetree.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/livetree.c b/livetree.c
> index cf2f63d..ef141a0 100644
> --- a/livetree.c
> +++ b/livetree.c
> @@ -526,7 +526,7 @@ struct node *get_node_by_path(struct node *tree, const char *path)
> p = strchr(path, '/');
>
> for_each_child(tree, child) {
> - if (p && strprefixeq(path, p - path, child->name))
> + if (p && strprefixeq(path, (size_t)(p - path), child->name))
> return get_node_by_path(child, p+1);
> else if (!p && streq(path, child->name))
> return child;
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2021-06-15 2:49 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-11 17:10 [PATCH v2 0/8] dtc: Fix signed/unsigned comparison warnings Andre Przywara
[not found] ` <20210611171040.25524-1-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2021-06-11 17:10 ` [PATCH v2 1/8] tests: Fix signedness comparisons warnings Andre Przywara
[not found] ` <20210611171040.25524-2-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2021-06-15 2:35 ` David Gibson
2021-06-18 17:00 ` Andre Przywara
[not found] ` <20210618180036.2ef17c4c-KTS7eRBhINUXU02nzanrWNbf9cGiqdzd@public.gmane.org>
2021-06-19 5:45 ` David Gibson
2021-06-11 17:10 ` [PATCH v2 2/8] fdtdump: " Andre Przywara
[not found] ` <20210611171040.25524-3-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2021-06-15 2:36 ` David Gibson
2021-06-11 17:10 ` [PATCH v2 3/8] fdtget: " Andre Przywara
[not found] ` <20210611171040.25524-4-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2021-06-15 2:44 ` David Gibson
2021-06-15 21:51 ` Andre Przywara
[not found] ` <20210615225133.4a597e7d-KTS7eRBhINUXU02nzanrWNbf9cGiqdzd@public.gmane.org>
2021-06-19 5:40 ` David Gibson
2021-06-11 17:10 ` [PATCH v2 4/8] dtc: Wrap phandle validity check Andre Przywara
[not found] ` <20210611171040.25524-5-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2021-06-15 2:46 ` David Gibson
2021-06-11 17:10 ` [PATCH v2 5/8] dtc: Fix signedness comparisons warnings: reservednum Andre Przywara
[not found] ` <20210611171040.25524-6-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2021-06-15 2:48 ` David Gibson
2021-06-11 17:10 ` [PATCH v2 6/8] dtc: Fix signedness comparisons warnings: pointer diff Andre Przywara
[not found] ` <20210611171040.25524-7-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2021-06-15 2:49 ` David Gibson [this message]
2021-06-11 17:10 ` [PATCH v2 7/8] checks: Fix signedness comparisons warnings Andre Przywara
[not found] ` <20210611171040.25524-8-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2021-06-15 2:55 ` David Gibson
2021-06-11 17:10 ` [PATCH v2 8/8] Makefile: add -Wsign-compare to warning options Andre Przywara
2021-06-15 2:56 ` [PATCH v2 0/8] dtc: Fix signed/unsigned comparison warnings David Gibson
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=YMgVO6w1oXki9b0G@yekko \
--to=david-xt8fgy+axnrb3ne2bgzf6laj5h9x9tb+@public.gmane.org \
--cc=andre.przywara-5wv7dgnIgG8@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).