Skip to content

Commit e751e0a

Browse files
fix TOKENIZE$ bug
1 parent 1e4e4b9 commit e751e0a

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

os/programs/webserver.rrbasic

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ ENDPROC
2020

2121
DEF PROCprocessRequest
2222
SOCKREAD client_socket, REQUEST$
23-
VERB$ = TOKENIZE$(REQUEST$, " ") ' Get the request details
24-
FILEPATH$ = TOKENIZE$(REQUEST$, " ")
23+
VERB$ = TRIM$(TOKENIZE$(REQUEST$, " ")) ' Get the request details
24+
FILEPATH$ = TRIM$(TOKENIZE$(REQUEST$, " "))
2525
IF FILEPATH$ = "/" THEN FILEPATH$ = "/index.html"
26-
PRINT FILEPATH$
27-
VERSION$ = REQUEST$
26+
VERSION$ = TRIM$(REQUEST$)
27+
PRINT VERB$; " -> "; FILEPATH$
2828
FILEPATH$ = "/system/webserver" + FILEPATH$
2929
FH = OPENIN(FILEPATH$)
3030
IF FH > -1 THEN

src/basic/string.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,9 @@ char* basic_tokenize(struct basic_ctx* ctx)
481481
if (ofs + split_len > len) {
482482
break;
483483
} else if (!strncmp(current_value, split, split_len)) {
484-
485-
size_t ret_len = ofs + split_len;
486-
size_t new_len = len - ret_len;
484+
size_t ret_len = ofs;
485+
size_t new_ofs = ofs + split_len;
486+
size_t new_len = len - new_ofs;
487487

488488
char* return_value = buddy_malloc(ctx->allocator, ret_len + 1);
489489
if (!return_value) {
@@ -501,7 +501,7 @@ char* basic_tokenize(struct basic_ctx* ctx)
501501
memcpy(return_value, old_value, ret_len);
502502
return_value[ret_len] = 0;
503503

504-
memcpy(new_value, old_value + ret_len, new_len);
504+
memcpy(new_value, old_value + new_ofs, new_len);
505505
new_value[new_len] = 0;
506506

507507
basic_set_string_variable(varname, new_value, ctx, false, false);

src/fs/filesystem.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,6 @@ int _open(const char* filename, int oflag)
723723
{
724724
fs_handle_type_t type = file_input;
725725
fs_directory_entry_t* file = NULL;
726-
/* First check if we can find the file in the filesystem */
727726

728727
if ((oflag & _O_APPEND) == _O_APPEND) {
729728
type = file_random;
@@ -737,16 +736,19 @@ int _open(const char* filename, int oflag)
737736
type = file_input;
738737
}
739738

739+
/* First check if we can find the file in the filesystem */
740740
file = fs_get_file_info(filename);
741741
if (file == NULL && type == file_input) {
742742
fs_set_error(FS_ERR_INVALID_FILEPATH);
743+
dprintf("_open: non-existent file %s\n", filename);
743744
return -1;
744745
} else if (file == NULL && type != file_input) {
745746
file = fs_create_file(filename, 0);
746747
} else if (file != NULL && type == file_output) {
747748
fs_truncate_file(file, 0);
748749
}
749750
if (file == NULL) {
751+
dprintf("_open: null file info for %s\n", filename);
750752
return -1;
751753
}
752754

@@ -755,6 +757,7 @@ int _open(const char* filename, int oflag)
755757
int fd = alloc_filehandle(type, file, IOBUFSZ, 0);
756758
if (fd == -1) {
757759
fs_set_error(FS_ERR_NO_MORE_FDS);
760+
dprintf("_open: out of descriptors opening %s\n", filename);
758761
return -1;
759762
}
760763

@@ -766,6 +769,7 @@ int _open(const char* filename, int oflag)
766769
* Give up the filehandle and return error.
767770
*/
768771
destroy_filehandle(fd);
772+
dprintf("_open: failed to read initial buffer for %s\n", filename);
769773
return -1;
770774
} else {
771775
if (file->size <= filehandles[fd]->inbufsize) {

0 commit comments

Comments
 (0)