Summary: | ReDim spills out of scope | ||
---|---|---|---|
Product: | LibreOffice | Reporter: | Joshua Coppersmith <joshua_coppersmith> |
Component: | BASIC | Assignee: | Not Assigned <libreoffice-bugs> |
Status: | UNCONFIRMED --- | ||
Severity: | normal | CC: | andreas.heinisch, himajin100000, mikekaganski, xiscofauli |
Priority: | medium | ||
Version: | 7.2.2.2 release | ||
Hardware: | x86-64 (AMD64) | ||
OS: | Linux (All) | ||
See Also: | https://bugs.documentfoundation.org/show_bug.cgi?id=133811 | ||
Whiteboard: | |||
Crash report or crash signature: | Regression By: |
Description
Joshua Coppersmith
2021-11-06 16:46:12 UTC
just a guess: should we prepare stack-thingy that holds dimensions for each block , pop and reset to that dimensions here https://opengrok.libreoffice.org/xref/core/basic/source/comp/loops.cxx?r=ab9b67bb#63 and before Parse() here? https://opengrok.libreoffice.org/xref/core/basic/source/comp/loops.cxx?r=ab9b67bb#74 and similar fix may be needed for single-line redim and for other branching syntax such as Switch-case. Another thing I'm just a bit concerned is "Go To" Statement. just a guess: Sub Main() Dim X() As Integer A: Redim X(1) Goto C: ' Probably While runtime gotes to C, Parser goes to B, not C. B: X(1,1) = 3 Exit Sub C: Redim X(1,1) Goto B: End Sub Looking at the following Sub StartUp1() Dim Passed(1 To 2) As Variant FuncBug1(Passed) End Sub Function FuncBug1(Passed() As Variant) Dim LocalDimmed(1 To 2) As Variant 'LocalDimmed(1, 1) = 42 'Will not compile for a locally Dimmed array Passed(1, 1) = 42 'Compiles and works, ignoring 2nd index MsgBox Passed(1, 1, 404, "Hi, how are you?") 'Shows 42 End Function we see--as a fun side note--that passed arrays may not even generate a runtime error with mismatched dimensions. This is harmless because when accessed with too many indices the code works, but when accessed with too few indices the runtime generates an 'Index out of defined range' error. Quirkiness aside, this leads to the question: Should an array passed to a function even be checked for dimension count at all at compile time if that makes no claims about operation at runtime? I get that the scoping issue would still exist for locally Dimmed arrays, but I am just wondering about the philosophy of issuing compile-time errors on things that can't really be checked statically anyway. @Andreas, @Mike, I thought you might be interested in this issue |