Skip to content

Commit 7963e17

Browse files
tidy up
1 parent 1a7c69e commit 7963e17

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

src/basic/string.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
*/
55
#include <kernel.h>
66

7+
extern struct basic_int_fn builtin_int[];
8+
extern struct basic_str_fn builtin_str[];
9+
extern struct basic_double_fn builtin_double[];
10+
711
char* basic_chr(struct basic_ctx* ctx)
812
{
913
PARAMS_START;
@@ -89,19 +93,6 @@ char* basic_lower(struct basic_ctx* ctx)
8993
return modified;
9094
}
9195

92-
extern struct basic_int_fn builtin_int[];
93-
extern struct basic_str_fn builtin_str[];
94-
extern struct basic_double_fn builtin_double[];
95-
96-
/*
97-
if (background) {
98-
code = map_vga_to_ansi_bg(vga_colour);
99-
} else {
100-
code = map_vga_to_ansi(vga_colour);
101-
}
102-
snprintf(out, out_len, "\x1b[%um", code);
103-
*/
104-
10596
char* basic_highlight(struct basic_ctx* ctx) {
10697
GENERATE_ENUM_STRING_NAMES(TOKEN, token_names)
10798
const size_t token_count = sizeof(token_names) / sizeof(*token_names);
@@ -115,7 +106,7 @@ char* basic_highlight(struct basic_ctx* ctx) {
115106
for (const char* pos = in; *pos; ++pos) {
116107
size_t current_len = strlen(out);
117108
bool found = false, reset_colour = false;
118-
if (in_comment) {
109+
if (in_comment && current_len < MAX_STRINGLEN - 1) {
119110
*(out + current_len) = *pos;
120111
continue;
121112
} else if (!in_quotes && *pos == '"') {
@@ -183,7 +174,7 @@ char* basic_highlight(struct basic_ctx* ctx) {
183174
} else if (!in_quotes && !in_comment && (*pos == '(' || *pos == ')' || *pos == '+' || *pos == '-' || *pos == '/' || *pos == '=' || *pos == '*' || *pos == '<' || *pos == '>' || *pos == ',' || *pos == ';')) {
184175
/* Symbolic maths colour */
185176
snprintf(out + current_len, MAX_STRINGLEN - current_len, "\x1b[%um%c\x1b[%um", map_vga_to_ansi(COLOUR_DARKRED), *pos, map_vga_to_ansi(COLOUR_WHITE));
186-
} else {
177+
} else if (current_len < MAX_STRINGLEN - 1) {
187178
*(out + current_len) = *pos;
188179
}
189180
}

0 commit comments

Comments
 (0)