You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2020/08/04 03:53:33 UTC

[incubator-nuttx] 02/04: drivers/usbhost/hid_parser.c: Fix out of range array accesses

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 59ba52aee8fd21442fa59ff4a04a30e6ff8d0c80
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Tue Aug 4 10:17:41 2020 +0900

    drivers/usbhost/hid_parser.c: Fix out of range array accesses
    
    Found by clang-check:
    
    usbhost/hid_parser.c:278:26: warning: Assigned value is garbage or undefined
                    usage[i] = usage[i + 1];
                             ^ ~~~~~~~~~~~~
    usbhost/hid_parser.c:321:34: warning: Assigned value is garbage or undefined
                            usage[i] = usage[i + 1];
                                     ^ ~~~~~~~~~~~~
    2 warnings generated.
---
 drivers/usbhost/hid_parser.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usbhost/hid_parser.c b/drivers/usbhost/hid_parser.c
index e87df56..00ee05e 100644
--- a/drivers/usbhost/hid_parser.c
+++ b/drivers/usbhost/hid_parser.c
@@ -274,8 +274,8 @@ int hid_parsereport(FAR const uint8_t *report, int rptlen,
             {
               collectionpath->usage.usage = usage[0];
 
-              for (i = 0; i < nusage; i++)
-                usage[i] = usage[i + 1];
+              for (i = 1; i < nusage; i++)
+                usage[i - 1] = usage[i];
 
               nusage--;
             }
@@ -316,9 +316,9 @@ int hid_parsereport(FAR const uint8_t *report, int rptlen,
                   {
                     newitem.attrib.usage.usage = usage[0];
 
-                    for (i = 0; i < nusage; i++)
+                    for (i = 1; i < nusage; i++)
                       {
-                        usage[i] = usage[i + 1];
+                        usage[i - 1] = usage[i];
                       }
                     nusage--;
                   }