Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 205bda1

Browse files
committed
[[ Bug 21326 ]] Preserve binary when modifying with data exec value
Previously when variables were modified by prepending values obtained from arrays, the checks for preserving binary strings were not correct as they failed to take into account that the exec value could be of valueref type but contain data. This patch changes the check to use the value's actual type code. Note the MCExecValue type is a union so the valueref_value field will occupy the same address as dataref_value - hence this version of the code will also work for exec values of dataref type.
1 parent 899cd79 commit 205bda1

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

docs/notes/bugfix-21326.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Ensure binary strings remain so when binary string is appended or prepended

engine/src/exec-engine.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,8 @@ void MCEngineExecPutIntoVariable(MCExecContext& ctxt, MCExecValue p_value, int p
704704
else
705705
{
706706
if (MCValueGetTypeCode(p_var . mark . text) == kMCValueTypeCodeData &&
707-
p_value . type == kMCExecValueTypeDataRef)
707+
MCExecTypeIsValueRef(p_value.type) &&
708+
MCValueGetTypeCode(p_value.valueref_value) == kMCValueTypeCodeData)
708709
{
709710
// AL-2014-11-20: Make sure the incoming exec value is released.
710711
MCAutoDataRef t_value_data;

engine/src/variable.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,8 @@ bool MCVariable::modify_ctxt(MCExecContext& ctxt, MCExecValue p_value, MCVariabl
613613

614614
bool MCVariable::modify_ctxt(MCExecContext& ctxt, MCExecValue p_value, MCSpan<MCNameRef> p_path, MCVariableSettingStyle p_setting)
615615
{
616-
if (p_value . type == kMCExecValueTypeDataRef)
616+
if (MCExecTypeIsValueRef(p_value.type) &&
617+
MCValueGetTypeCode(p_value.valueref_value) == kMCValueTypeCodeData)
617618
{
618619
if (can_become_data(ctxt, p_path))
619620
{
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
script "CoreEnginePut"
2+
/*
3+
Copyright (C) 2018 LiveCode Ltd.
4+
5+
This file is part of LiveCode.
6+
7+
LiveCode is free software; you can redistribute it and/or modify it under
8+
the terms of the GNU General Public License v3 as published by the Free
9+
Software Foundation.
10+
11+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
12+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
18+
19+
// Test MCVariable::modify variant
20+
on TestPutAfterData
21+
local tVar
22+
put numToByte(1) into tVar
23+
put numToByte(1) after tVar
24+
TestAssert "put after preserves binary string", \
25+
tVar is strictly a binary string
26+
end TestPutAfterData
27+
28+
// Test MCEngineExecPutIntoVariable ValueRef chunk variant
29+
on TestPutAfterDataChunk
30+
local tVar, tArray
31+
put numToByte(1) into tVar
32+
put numToByte(1) after byte 1 of tVar
33+
TestAssert "put after chunk preserves binary string", \
34+
tVar is strictly a binary string
35+
end TestPutAfterDataChunk
36+
37+
// Test MCVariable::modify_ctxt variant
38+
on TestPutAfterDataExecValue
39+
local tVar, tArray
40+
put numToByte(1) into tVar
41+
put numToByte(1) into tArray[1]
42+
put tArray[1] after tVar
43+
TestAssert "put as execvalue after preserves binary string", \
44+
tVar is strictly a binary string
45+
end TestPutAfterDataExecValue
46+
47+
// Test MCEngineExecPutIntoVariable ExecValue chunk variant
48+
on TestPutAfterDataChunkExecValue
49+
local tVar, tArray
50+
put numToByte(1) into tVar
51+
put numToByte(1) into tArray[1]
52+
put tArray[1] after byte 1 of tVar
53+
TestAssert "put as execvalue after chunk preserves binary string", \
54+
tVar is strictly a binary string
55+
end TestPutAfterDataChunkExecValue

0 commit comments

Comments
 (0)