Skip to content

Commit 1d26b96

Browse files
committed
[22079] Fix crash when putting before/after an invalid container
1 parent c778af7 commit 1d26b96

File tree

3 files changed

+125
-2
lines changed

3 files changed

+125
-2
lines changed

docs/notes/bugfix-22079.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Fix crash when putting before/after an invalid container

engine/src/chunk.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,8 +2221,22 @@ bool MCChunk::set(MCExecContext &ctxt, Preposition_type p_type, MCExecValue p_va
22212221
MCInterfaceExecPutIntoField(ctxt, *t_string, p_type, t_obj_chunk);
22222222
}
22232223
else
2224-
MCInterfaceExecPutIntoObject(ctxt, p_value, p_type, t_obj_chunk);
2225-
2224+
{
2225+
// AL-2014-08-04: [[ Bug 13081 ]] 'put into <chunk>' is valid for any container type
2226+
switch (t_obj_chunk . object -> gettype())
2227+
{
2228+
case CT_BUTTON:
2229+
case CT_IMAGE:
2230+
case CT_AUDIO_CLIP:
2231+
case CT_VIDEO_CLIP:
2232+
MCInterfaceExecPutIntoObject(ctxt, p_value, p_type, t_obj_chunk);
2233+
break;
2234+
default:
2235+
ctxt . LegacyThrow(EE_CHUNK_SETNOTACONTAINER);
2236+
break;
2237+
}
2238+
}
2239+
22262240
MCValueRelease(t_obj_chunk . mark . text);
22272241
}
22282242

tests/lcs/core/engine/put.livecodescript

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,114 @@ for more details.
1616
You should have received a copy of the GNU General Public License
1717
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
1818

19+
20+
on _TestPutBeforeInvalidContainer pContainer
21+
local tDo
22+
put "put" && quote & foo & quote && "before" && pContainer into tDo
23+
do tDo
24+
end _TestPutBeforeInvalidContainer
25+
26+
on _TestPutIntoInvalidContainer pContainer
27+
local tDo
28+
put "put" && quote & foo & quote && "into" && pContainer into tDo
29+
do tDo
30+
end _TestPutIntoInvalidContainer
31+
32+
on _TestPutAfterInvalidContainer pContainer
33+
local tDo
34+
put "put" && quote & foo & quote && "after" && pContainer into tDo
35+
do tDo
36+
end _TestPutAfterInvalidContainer
37+
38+
on TestPutBeforeIntoAfterInvalidContainer
39+
40+
local tCardID, tStackID
41+
42+
create stack "myTestStack"
43+
put it into tStackID
44+
45+
set the defaultstack to tStackID
46+
put the long ID of this card into tCardID
47+
48+
49+
// card
50+
TestAssertThrow "put before invalid container" && tCardID, "_TestPutBeforeInvalidContainer", the long id of me, \
51+
"EE_CHUNK_SETNOTACONTAINER", tCardID
52+
TestAssertThrow "put into invalid container" , "_TestPutIntoInvalidContainer", the long id of me, \
53+
"EE_CHUNK_SETNOTACONTAINER", tCardID
54+
TestAssertThrow "put after invalid container" , "_TestPutAfterInvalidContainer", the long id of me, \
55+
"EE_CHUNK_SETNOTACONTAINER", tCardID
56+
57+
// stack
58+
TestAssertThrow "put before invalid container" && tStackID , "_TestPutBeforeInvalidContainer", the long id of me, \
59+
"EE_CHUNK_SETNOTACONTAINER", tStackID
60+
TestAssertThrow "put into invalid container" , "_TestPutIntoInvalidContainer", the long id of me, \
61+
"EE_CHUNK_SETNOTACONTAINER", tStackID
62+
TestAssertThrow "put after invalid container" , "_TestPutAfterInvalidContainer", the long id of me, \
63+
"EE_CHUNK_SETNOTACONTAINER", tStackID
64+
65+
// widget
66+
local tWidgetID
67+
create widget "myClock" as "com.livecode.widget.clock"
68+
put it into tWidgetID
69+
TestAssertThrow "put before invalid container" && tWidgetID, "_TestPutBeforeInvalidContainer", the long id of me, \
70+
"EE_CHUNK_SETNOTACONTAINER", tWidgetID
71+
TestAssertThrow "put into invalid container" , "_TestPutIntoInvalidContainer", the long id of me, \
72+
"EE_CHUNK_SETNOTACONTAINER", tWidgetID
73+
TestAssertThrow "put after invalid container" , "_TestPutAfterInvalidContainer", the long id of me, \
74+
"EE_CHUNK_SETNOTACONTAINER", tWidgetID
75+
76+
77+
repeat for each item tContainer in "scrollbar,group,player,graphic,eps"
78+
local tID
79+
local tDo
80+
put "create" && tContainer && "myContainer" into tDo
81+
do tDo
82+
put it into tID
83+
TestAssertThrow "put before invalid container:" && tContainer, "_TestPutBeforeInvalidContainer", the long id of me, \
84+
"EE_CHUNK_SETNOTACONTAINER", tID
85+
TestAssertThrow "put into invalid container" && tContainer, "_TestPutIntoInvalidContainer", the long id of me, \
86+
"EE_CHUNK_SETNOTACONTAINER", tID
87+
TestAssertThrow "put after invalid container" && tContainer, "_TestPutAfterInvalidContainer", the long id of me, \
88+
"EE_CHUNK_SETNOTACONTAINER", tID
89+
delete tID
90+
end repeat
91+
92+
delete stack "myTestStack"
93+
end TestPutBeforeIntoAfterInvalidContainer
94+
95+
on TestPutBeforeIntoAfterValidContainer
96+
97+
local tStackID
98+
99+
create stack "myTestStack"
100+
put it into tStackID
101+
102+
set the defaultstack to tStackID
103+
104+
// button case
105+
create button "myNewButton"
106+
put "bar" into button "myNewButton"
107+
put "foo" before button "myNewButton"
108+
put "baz" after button "myNewButton"
109+
TestAssert "Can put before|into|after a button", the text of button "myNewButton" is "foobarbaz"
110+
delete button "myNewButton"
111+
112+
113+
// image case
114+
repeat for each item tWhere in "before,into,after"
115+
create image "foo"
116+
local tDo
117+
put "put empty" && tWhere && "image" && quote & "foo" & quote into tDo
118+
do tDo
119+
TestAssert "Can put" && tWhere && "an image", the text of image "foo" is empty
120+
delete image "foo"
121+
end repeat
122+
123+
124+
end TestPutBeforeIntoAfterValidContainer
125+
126+
19127
// Test MCVariable::modify variant
20128
on TestPutAfterData
21129
local tVar

0 commit comments

Comments
 (0)