mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
fix stack overflow issue
This commit is contained in:
@@ -232,8 +232,8 @@ static int nativeRead(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments)
|
|||||||
case TOY_LITERAL_STRING:
|
case TOY_LITERAL_STRING:
|
||||||
{
|
{
|
||||||
char value[TOY_MAX_STRING_LENGTH] = {0};
|
char value[TOY_MAX_STRING_LENGTH] = {0};
|
||||||
fread(value, sizeof(char), sizeof(value) - 1, file->fp);
|
fread(value, sizeof(char), TOY_MAX_STRING_LENGTH - 1, file->fp);
|
||||||
value[TOY_MAX_STRING_LENGTH] = '\0';
|
value[TOY_MAX_STRING_LENGTH - 1] = '\0';
|
||||||
|
|
||||||
resultLiteral = TOY_TO_STRING_LITERAL(Toy_createRefString(value));
|
resultLiteral = TOY_TO_STRING_LITERAL(Toy_createRefString(value));
|
||||||
|
|
||||||
|
|||||||
3
test/scripts/lib/file/inputs.txt
Normal file
3
test/scripts/lib/file/inputs.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
8
|
||||||
|
12.5
|
||||||
|
test
|
||||||
2
test/scripts/lib/file/outputs.txt
Normal file
2
test/scripts/lib/file/outputs.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
8
|
||||||
|
12.500000
|
||||||
@@ -19,25 +19,27 @@ fn reset() {
|
|||||||
|
|
||||||
// test read
|
// test read
|
||||||
{
|
{
|
||||||
// // enter test
|
var reader = open("scripts:/lib/file/inputs.txt", "r");
|
||||||
// assert input.read(string) == "test\n", "read string failed";
|
|
||||||
|
|
||||||
// // enter 8
|
assert reader.read(int) == 8, "read int failed";
|
||||||
// assert input.read(int) == 8, "read int failed";
|
assert reader.read(float) == 12.5, "read float failed";
|
||||||
|
assert reader.read(string) == "\ntest\n", "read string failed";
|
||||||
|
|
||||||
// // enter 12.5
|
// invaild types
|
||||||
// assert input.read(float) == 12.5, "read float failed";
|
assert input.read(type) == null, "read type failed";
|
||||||
|
assert input.read(any) == null, "read any failed";
|
||||||
|
|
||||||
// // invaild types
|
reader.close();
|
||||||
// assert input.read(type) == null, "read type failed";
|
|
||||||
// assert input.read(any) == null, "read any failed";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// test write
|
// test write
|
||||||
{
|
{
|
||||||
assert output.write(8) == true, "write int failed";
|
var writer = open("scripts:/lib/file/outputs.txt", "w");
|
||||||
assert output.write("\n") == true, "write string failed";
|
assert writer.write(8) == true, "write int failed";
|
||||||
assert output.write(12.5) == true, "write float failed";
|
assert writer.write("\n") == true, "write string failed";
|
||||||
|
assert writer.write(12.5) == true, "write float failed";
|
||||||
|
|
||||||
|
writer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user