Menu

#317 no error when fixed-length array inside a for loop

open
nobody
None
2024-04-07
2024-02-02
No

the following code has compile with "-exx" should reveals the array out-of-bound error, but not.

DIM DataArray(0 to 1) AS DOUBLE
DIM i as ULONG

FOR i=0 TO 2
  DataArray(i) = 1
NEXT i

Discussion

  • Michelle.Tsai

    Michelle.Tsai - 2024-02-02

    But this will return compile error with "Array out-of-bounds"

    DIM DataArray(0 to 1) AS DOUBLE
    DIM i as INTEGER
    
    DataArray(0)=0
    DataArray(1)=0
    DataArray(2)=0
    
     
  • fxm (freebasic.net)

    With the first code, I get the runtime error:

    Aborting due to runtime error 6 (out of bounds array access) at line 5 of C:.....

     
  • Michelle.Tsai

    Michelle.Tsai - 2024-02-02

    information of freebasic:

    FreeBASIC Compiler - Version 1.07.1 (2024-01-29), built for linux (32bit)
    Copyright (C) 2004-2019 The FreeBASIC development team.

    Is there any chance that different result cause by freebasic version?

     

    Last edit: Michelle.Tsai 2024-02-02
  • fxm (freebasic.net)

    Take the opportunity to update your FreeBASIC to the latest official version (1.10).
    This is normally the thing to do before writing a bug report.

     
  • Michelle.Tsai

    Michelle.Tsai - 2024-02-02

    I've update to 1.10, and it shows nothing "after compile", actually it's shows error when "run" the file.
    The question is that we expect the error shows "when compile the code", not after compile and "runs it".

    terminal link
    terminal image

     
  • Michelle.Tsai

    Michelle.Tsai - 2024-02-02

    FYI

    DIM DataArray(0 to 1) AS DOUBLE
    DIM i as INTEGER
    
    DataArray(0)=0
    DataArray(1)=0
    DataArray(2)=0
    

    above code shows error when compile

    fbc ./emmc/data/AMI/AMI_Work_Project/Task0.bas  -exx
    ./emmc/data/AMI/AMI_Work_Project/Task0.bas(3) error 92: Array out-of-bounds, found ')' in 'DataArray(2) = 0'
    
     
  • fxm (freebasic.net)

    As soon as the array index is a variable and not a constant, the error message can only be shown at runtime, otherwise some sort of interpreter would be required to catch the error before.

     

    Last edit: fxm (freebasic.net) 2024-02-02
  • Jeff Marshall

    Jeff Marshall - 2024-04-07

    To catch this kind of error at compile time would require capability for static analysis, which is likely hundreds and hundreds of hours to implement, or a rewrite of the compiler. Moved to feature requests.

     
  • Jeff Marshall

    Jeff Marshall - 2024-04-07

    Ticket moved from /p/fbc/bugs/1002/

    Can't be converted:

    • _component: compiler
     

Log in to post a comment.

MongoDB Logo MongoDB