diff mbox

[U-Boot] sandbox: Fix comparison of unsigned enum expression warning

Message ID 1494720690-30488-1-git-send-email-trini@konsulko.com
State Accepted
Commit e2bc87d41ce866b30721d5b8ee395efefecd9bef
Delegated to: Simon Glass
Headers show

Commit Message

Tom Rini May 14, 2017, 12:11 a.m. UTC
In os_dirent_get_typename() we are checking that type falls within the
known values of the enum os_dirent_t.  With clang-3.8 testing this value
as being >= 0 results in a warning as it will always be true.  This
assumes of course that we are only given valid data.  Given that we want
to sanity check the input, we change this to check that it falls within
the range of the first to the last entry in the given enum.

Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Tom Rini <trini@konsulko.com>
---
 arch/sandbox/cpu/os.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Simon Glass May 15, 2017, 3:03 a.m. UTC | #1
On 13 May 2017 at 18:11, Tom Rini <trini@konsulko.com> wrote:
> In os_dirent_get_typename() we are checking that type falls within the
> known values of the enum os_dirent_t.  With clang-3.8 testing this value
> as being >= 0 results in a warning as it will always be true.  This
> assumes of course that we are only given valid data.  Given that we want
> to sanity check the input, we change this to check that it falls within
> the range of the first to the last entry in the given enum.
>
> Cc: Simon Glass <sjg@chromium.org>
> Signed-off-by: Tom Rini <trini@konsulko.com>
> ---
>  arch/sandbox/cpu/os.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Simon Glass June 7, 2017, 1:47 a.m. UTC | #2
On 13 May 2017 at 18:11, Tom Rini <trini@konsulko.com> wrote:
> In os_dirent_get_typename() we are checking that type falls within the
> known values of the enum os_dirent_t.  With clang-3.8 testing this value
> as being >= 0 results in a warning as it will always be true.  This
> assumes of course that we are only given valid data.  Given that we want
> to sanity check the input, we change this to check that it falls within
> the range of the first to the last entry in the given enum.
>
> Cc: Simon Glass <sjg@chromium.org>
> Signed-off-by: Tom Rini <trini@konsulko.com>
> ---
>  arch/sandbox/cpu/os.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-dm, thanks!
diff mbox

Patch

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 35ea00ce3ca0..7243bfc1b1fd 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -395,7 +395,7 @@  const char *os_dirent_typename[OS_FILET_COUNT] = {
 
 const char *os_dirent_get_typename(enum os_dirent_t type)
 {
-	if (type >= 0 && type < OS_FILET_COUNT)
+	if (type >= OS_FILET_REG && type < OS_FILET_COUNT)
 		return os_dirent_typename[type];
 
 	return os_dirent_typename[OS_FILET_UNKNOWN];