Skip to content

Commit def3c87

Browse files
committed
com.livecode.foreign: Correctly implement "copy" for NativeCString.
The existing implementation copied the pointer to the original string rather than the original string itself.
1 parent 3c3f256 commit def3c87

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

libscript/src/module-foreign.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,17 @@ static bool __cstring_copy(void *from, void *to)
5858
*(void **)to = nil;
5959
return true;
6060
}
61+
62+
const char *t_old_string = *(char **) from;
6163

6264
size_t t_length;
63-
t_length = strlen(*(char **)from) + 1;
65+
t_length = strlen(t_old_string) + 1;
6466

6567
char *t_new_string;
6668
if (!MCMemoryNewArray(t_length, t_new_string))
6769
return false;
6870

69-
MCMemoryCopy(t_new_string, from, t_length);
71+
MCMemoryCopy(t_new_string, t_old_string, t_length);
7072

7173
*(char **)to = t_new_string;
7274

0 commit comments

Comments
 (0)