Skip to content

Commit c42e14e

Browse files
committed
Fix hard crash in #declare Foo[A][B]=... if Foo is an array of arrays and Foo[A] is uninitialized.
1 parent 669144e commit c42e14e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

changes.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ Reported via GitHub:
7979

8080
Reported via the Newsgroups:
8181

82+
83+
(2018-08-27, povray.advanced-users, "Re: It gets even weirder.")
84+
Trying to `#declare Foo[A][B]=...` with `Foo` being an array of arrays and
85+
`Foo[A]` not yet initialized causes a hard crash instead of a parse error.
8286
8387
(2017-11-05, povray.newusers, "orthographic camera and conic_sweep object")
8488
Sides of a `conic_sweep` prism become invisible when viewed head-on using

source/parser/parser_tokenizer.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,11 @@ void Parser::Read_Symbol()
14791479
a = reinterpret_cast<POV_ARRAY *>(*(Token.DataPtr));
14801480
j = 0;
14811481

1482+
if (a == nullptr)
1483+
// This happens in e.g. `#declare Foo[A][B]=...` when `Foo` is an
1484+
// array of arrays and `Foo[A]` is uninitialized.
1485+
Error("Attempt to access uninitialized nested array.");
1486+
14821487
for (i=0; i <= a->Dims; i++)
14831488
{
14841489
Parse_Square_Begin();
@@ -1507,6 +1512,11 @@ void Parser::Read_Symbol()
15071512

15081513
if (!LValue_Ok && !Inside_Ifdef)
15091514
{
1515+
// Note that this does not (and must not) trigger in e.g.
1516+
// `#declare Foo[A][B]=...` when `Foo` is an array of arrays and
1517+
// `Foo[A]` is uninitialized, because until now we've only seen
1518+
// `#declare Foo[A]`, which is no reason for concern as it may
1519+
// just as well be part of `#declare Foo[A]=...` which is fine.
15101520
if (a->DataPtrs[j] == NULL)
15111521
Error("Attempt to access uninitialized array element.");
15121522
}

0 commit comments

Comments
 (0)