Skip to content

Commit b18dba2

Browse files
committed
COMMON: fix potential crash with some STR funcs
1 parent 6fcc485 commit b18dba2

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

samples/distro-examples/tests/strings.bas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,5 +169,6 @@ sub cmd_str1(n)
169169
x=tab(n)
170170
end
171171
cmd_str1("")
172+
cmd_str1(0)
172173

173174

src/common/blib_func.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ void cmd_str1(long funcCode, var_t *arg, var_t *r) {
934934
// convert C-Style string to BASIC-style string
935935
//
936936
if (!v_is_type(arg, V_STR)) {
937-
v_init(arg);
937+
v_init(r);
938938
break;
939939
}
940940
r->v.p.ptr = cstrdup(arg->v.p.ptr);
@@ -946,7 +946,7 @@ void cmd_str1(long funcCode, var_t *arg, var_t *r) {
946946
// convert BASIC-Style string to C-style string
947947
//
948948
if (!v_is_type(arg, V_STR)) {
949-
v_init(arg);
949+
v_init(r);
950950
break;
951951
}
952952
r->v.p.ptr = bstrdup(arg->v.p.ptr);
@@ -1016,7 +1016,7 @@ void cmd_str1(long funcCode, var_t *arg, var_t *r) {
10161016
// str <- LTRIM$(s)
10171017
//
10181018
if (!v_is_type(arg, V_STR)) {
1019-
v_init(arg);
1019+
v_init(r);
10201020
break;
10211021
}
10221022
p = arg->v.p.ptr;
@@ -1036,7 +1036,7 @@ void cmd_str1(long funcCode, var_t *arg, var_t *r) {
10361036
// str <- RTRIM$(s)
10371037
//
10381038
if (!v_is_type(arg, V_STR)) {
1039-
v_init(arg);
1039+
v_init(r);
10401040
break;
10411041
}
10421042
p = arg->v.p.ptr;

src/platform/console/dev_null.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void osd_setxy(int x, int y) {
6262
* Basic output - print sans control codes
6363
*/
6464
void osd_write(const char *str) {
65-
int len = str == NULL ? 0 : strlen(str);
65+
int len = strlen(str);
6666
if (len) {
6767
int i, index = 0, escape = 0;
6868
char *buffer = (char *)malloc(len + 1);

0 commit comments

Comments
 (0)