scsi: isci: avoid array subscript warning
authorArnd Bergmann <arnd@arndb.de>
Fri, 18 Nov 2016 16:14:01 +0000 (17:14 +0100)
committerMartin K. Petersen <martin.petersen@oracle.com>
Tue, 29 Nov 2016 16:46:08 +0000 (11:46 -0500)
I'm getting a new warning with gcc-7:

isci/remote_node_context.c: In function 'sci_remote_node_context_destruct':
isci/remote_node_context.c:69:16: error: array subscript is above array bounds [-Werror=array-bounds]

This is odd, since we clearly cover all values for enum
scis_sds_remote_node_context_states here. Anyway, checking for an array
overflow can't harm and it makes the warning go away.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/isci/remote_node_context.c

index 30bd80052e03cc83ded65de8ef8b6c49133d4f68..e3f2a5359d71e11118dd204d92b3410cfbe39722 100644 (file)
@@ -66,6 +66,9 @@ const char *rnc_state_name(enum scis_sds_remote_node_context_states state)
 {
        static const char * const strings[] = RNC_STATES;
 
+       if (state >= ARRAY_SIZE(strings))
+               return "UNKNOWN";
+
        return strings[state];
 }
 #undef C