Skip to content

Commit fa37beb

Browse files
committed
COMMON: handle octal escapes correctly
1 parent fd6252a commit fa37beb

File tree

5 files changed

+34
-28
lines changed

5 files changed

+34
-28
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2021-01-18 (12.21)
2+
COMMON: Handle octal escapes correctly
3+
14
2020-12-19 (12.20)
25
SDL: Update editor popup appearance
36

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dnl This program is distributed under the terms of the GPL v2.0
77
dnl Download the GNU Public License (GPL) from www.gnu.org
88
dnl
99

10-
AC_INIT([smallbasic], [12.20])
10+
AC_INIT([smallbasic], [12.21])
1111
AC_CONFIG_SRCDIR([configure.ac])
1212

1313
AC_CANONICAL_TARGET

src/common/bc.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@ int bc_is_escape(char c, char *value) {
4040
return result;
4141
}
4242

43+
/*
44+
* whether the character is octal escape
45+
*/
46+
int bc_is_octal(char *str, char *output) {
47+
char *next = str + 1;
48+
int result = 0;
49+
int digits = 0;
50+
int value = 0;
51+
52+
while (isdigit(*next) && digits < 4) {
53+
value = (value << 3) + (*next - '0');
54+
digits++;
55+
next++;
56+
}
57+
if (digits == 3 && value < 256) {
58+
*output = value;
59+
result = 1;
60+
}
61+
return result;
62+
}
63+
4364
/*
4465
* Create a bytecode segment
4566
*/
@@ -240,7 +261,15 @@ char *bc_store_string(bc_t *bc, char *src) {
240261
char code[] = {escape, '\0'};
241262
cstr_append_i(&cs, base, p - base);
242263
cstr_append_i(&cs, code, 1);
264+
// skip single escape character
243265
base = (++p) + 1;
266+
} else if (*p == '\\' && bc_is_octal(p, &escape)) {
267+
char code[] = {escape, '\0'};
268+
cstr_append_i(&cs, base, p - base);
269+
cstr_append_i(&cs, code, 1);
270+
// skip octal digits
271+
p += 3;
272+
base = p + 1;
244273
} else if (*p == V_QUOTE) {
245274
// revert hidden quote
246275
*p = '\"';

src/common/scan.c

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3942,29 +3942,6 @@ char *comp_load(const char *file_name) {
39423942
return buf;
39433943
}
39443944

3945-
const char *format_numeric_text(const char *str, char **output) {
3946-
const char *result = str + 1;
3947-
int value = 0;
3948-
int digits = 0;
3949-
3950-
while (isdigit(*result)) {
3951-
value = (value << 3) + (*result - '0');
3952-
digits++;
3953-
result++;
3954-
}
3955-
3956-
if (digits == 3 && value > V_JOIN_LINE && value < 256) {
3957-
**output = value;
3958-
} else {
3959-
**output = *str;
3960-
result = str + 1;
3961-
}
3962-
3963-
(*output)++;
3964-
3965-
return result;
3966-
}
3967-
39683945
/**
39693946
* format source-code text
39703947
*
@@ -4173,9 +4150,6 @@ char *comp_format_text(const char *source) {
41734150
}
41744151
// new line auto-ends the quoted string
41754152
quotes = !quotes;
4176-
} else if (*p == '\\') {
4177-
p = format_numeric_text(p, &ps);
4178-
continue;
41794153
}
41804154
*ps++ = *p++;
41814155
}

src/platform/android/app/src/main/assets/main.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ sub do_about()
124124
color colText
125125
print "Version "; sbver
126126
print
127-
print "Copyright (c) 2002-2020 Chris Warren-Smith"
127+
print "Copyright (c) 2002-2021 Chris Warren-Smith"
128128
print "Copyright (c) 1999-2006 Nicholas Christopoulos" + chr(10)
129129

130130
local bn_home

0 commit comments

Comments
 (0)