Bug 89860 - liboffloadmic/runtime/offload_target.cpp:332]: (style) Array index 'i' is used before limits check.
Summary: liboffloadmic/runtime/offload_target.cpp:332]: (style) Array index 'i' is use...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: other (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: cppcheck
  Show dependency treegraph
 
Reported: 2019-03-27 19:51 UTC by David Binderman
Modified: 2020-05-05 14:01 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-03-28 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Binderman 2019-03-27 19:51:29 UTC
Source code is

            if (m_vars[i].type.dst == c_extended_type && i < vars_total) {

it might be wise to sanity check i before use, not after.
Comment 1 Richard Biener 2019-03-28 09:57:58 UTC
Confirmed.  But the code is probably unmaintained - HJ, whose the Intel contact to work on MIC (or is it time to rip out intelmic support given Knights-* is dead?)
Comment 2 Hongtao.liu 2019-03-29 01:53:08 UTC
    
The code is like:

for (int i = 0; i < m_vars_total; i++) {
  // instead of m_vars[i].type.src we will use m_vars_extra[i].type_src

   if (i < vars_total) {
  
    ......
  
    if (m_vars[i].type.dst == c_extended_type && i < vars_total)
  
    ......
  
   }

......

}

So the later ***i < vars_total*** is not actually needed.
Comment 3 Eric Gallager 2019-09-29 04:18:38 UTC
svn blame says Ilya Verbin wrote this code; cc-ing
Comment 4 GCC Commits 2020-05-05 13:59:55 UTC
The master branch has been updated by Martin Liska <marxin@gcc.gnu.org>:

https://gcc.gnu.org/g:98f7381d17a1ad47773b70a5de7d94a164357916

commit r11-75-g98f7381d17a1ad47773b70a5de7d94a164357916
Author: Martin Liska <mliska@suse.cz>
Date:   Tue Feb 4 14:57:59 2020 +0100

    Put index check before use.
    
    liboffloadmic/ChangeLog:
    
    2020-02-04  Martin Liska  <mliska@suse.cz>
    
            PR other/89860
            * runtime/offload_target.cpp: Put index check
            before its use.
Comment 5 Martin Liška 2020-05-05 14:01:24 UTC
Fixed on master.