Menu

#5 IndexError: string index out of range

v1.0 (example)
closed
None
5
2014-07-12
2007-11-19
No

Hello;

I passed flawfinder over the Salome Project ( FEA -CAD opensource project and I got this:

kakumen# flawfinder -Q -i ./src3.2.6 > flaws.txt
Traceback (most recent call last):
File "/usr/local/bin/flawfinder", line 1863, in <module>
flawfind()
File "/usr/local/bin/flawfinder", line 1857, in flawfind
if process_files():
File "/usr/local/bin/flawfinder", line 1713, in process_files
process_file_args(files, patch_infos)
File "/usr/local/bin/flawfinder", line 1522, in process_file_args
maybe_process_file(f, patch_infos)
File "/usr/local/bin/flawfinder", line 1473, in maybe_process_file
maybe_process_file(os.path.join(f, file), patch_infos)
File "/usr/local/bin/flawfinder", line 1473, in maybe_process_file
maybe_process_file(os.path.join(f, file), patch_infos)
File "/usr/local/bin/flawfinder", line 1473, in maybe_process_file
maybe_process_file(os.path.join(f, file), patch_infos)
File "/usr/local/bin/flawfinder", line 1473, in maybe_process_file
maybe_process_file(os.path.join(f, file), patch_infos)
File "/usr/local/bin/flawfinder", line 1493, in maybe_process_file
process_c_file(f, patch_infos)
File "/usr/local/bin/flawfinder", line 1303, in process_c_file
c = text[i]
IndexError: string index out of range

Discussion

  • Nobody/Anonymous

    Logged In: NO

    It seems, that sometimes after calling i = m.end(0) (line 1301) i gets set to file length. Then accessing text[i] causes this exception.
    I've just encountered this problem, and IMHO it's rather simple to fix. After i = m.end(0) add (at line 1302) following:
    if i == len(text):
    continue
    (indentation is important)
    and flawfinder will begin to work perfectly.

    BS.

     
  • Pedro F. Giffuni

    Patch

     
  • Pedro F. Giffuni

    Logged In: YES
    user_id=678384
    Originator: YES

    Hello;

    I can confirm the suggested change fixed the bug. Thanks!
    File Added: patch-flawfinder

     
  • Philippe Ombredanne

    Bug confirmed indeed:
    Here is a minimal c+ file that shows the problem for testing, note that all whitespace matter:
    the file ends with a line with only four spaces
    =======================
    void some()
    {/*some*/}

    =======================

     
  • Geoffrey Hunter

    Geoffrey Hunter - 2014-07-11

    Bug still occurs, I guess this hadn't been fixed yet! (8 years on...). No development anymore? Release to GitHub and we can fork it, fix it!

     
  • David A. Wheeler

    You can fork now on SourceForge, go to the "code" page.

    That said, fair point, I need to get moving on this.

     
  • David A. Wheeler

    Okay, I've patched it in the development version. I plan to release a new version relatively soon that fixes it. Independent testing is very welcome!

     
  • David A. Wheeler

    • status: open --> closed
    • assigned_to: David A. Wheeler
    • Group: --> v1.0 (example)
     
  • David A. Wheeler

    All fixed.

     
  • Geoffrey Hunter

    Geoffrey Hunter - 2014-07-12

    Kudos for fixing!

     

Log in to post a comment.