Skip to content

Commit df98828

Browse files
marsupiallgritz
authored andcommitted
Fix oslc crash with invalid field selection. (#835)
1 parent cb9935c commit df98828

File tree

6 files changed

+30
-5
lines changed

6 files changed

+30
-5
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ TESTSUITE ( and-or-not-synonyms aastep arithmetic array array-derivs array-range
265265
pnoise pnoise-cell pnoise-gabor pnoise-perlin pnoise-uperlin
266266
operator-overloading
267267
oslc-comma oslc-D
268-
oslc-err-arrayindex oslc-err-closuremul
268+
oslc-err-arrayindex oslc-err-closuremul oslc-err-field
269269
oslc-err-format oslc-err-intoverflow
270270
oslc-err-noreturn oslc-err-notfunc
271271
oslc-err-outputparamvararray oslc-err-paramdefault

src/liboslcomp/ast.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,8 @@ ASTstructselect::find_fieldsym (int &structid, int &fieldid)
628628
{
629629
if (! lvalue()->typespec().is_structure() &&
630630
! lvalue()->typespec().is_structure_array()) {
631+
error ("type '%s' does not have a member '%s'",
632+
type_c_str(lvalue()->typespec()), m_field);
631633
return NULL;
632634
}
633635

src/liboslcomp/codegen.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,10 +1873,13 @@ ASTfunction_call::codegen_arg (SymbolPtrVec &argdest, SymbolPtrVec &index1,
18731873
form->typespec().c_str());
18741874
}
18751875
}
1876-
argdest.push_back (thisarg);
1877-
index1.push_back (ind1);
1878-
index2.push_back (ind2);
1879-
index3.push_back (ind3);
1876+
if (thisarg) {
1877+
argdest.push_back (thisarg);
1878+
index1.push_back (ind1);
1879+
index2.push_back (ind2);
1880+
index3.push_back (ind3);
1881+
} else
1882+
arg->error("Invalid argument to function");
18801883
}
18811884

18821885

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test.osl:8: error: type 'color' does not have a member 'nope'
2+
test.osl:11: error: struct type 'custom' does not have a member 'bad'
3+
FAILED test.osl

testsuite/oslc-err-field/run.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env python
2+
3+
# command = oslc("test.osl")
4+
# don't even need that -- it's automatic
5+
failureok = 1 # this test is expected to have oslc errors

testsuite/oslc-err-field/test.osl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Test invalid field selections in function calls
2+
3+
struct custom { float field; };
4+
5+
shader test ()
6+
{
7+
color c = color(4,3,2);
8+
printf("c.nope: %g\n", c.nope);
9+
10+
custom cc = { 1 };
11+
printf("cc.bad: %g\n", cc.bad);
12+
}

0 commit comments

Comments
 (0)