From e4d843ad3a4a16cfd2ac5e40878d98063ca60738 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 27 Jan 2023 06:16:39 +0000 Subject: [PATCH] Type check --- repl/lib_runner.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/repl/lib_runner.c b/repl/lib_runner.c index 32c7350..50b9576 100644 --- a/repl/lib_runner.c +++ b/repl/lib_runner.c @@ -581,13 +581,19 @@ Toy_LiteralDictionary* Toy_getDriveDictionary() { } Toy_Literal Toy_getFilePathLiteral(Toy_Interpreter* interpreter, Toy_Literal* drivePathLiteral) { + //check argument types + if (!TOY_IS_STRING(*drivePathLiteral)) { + interpreter->errorOutput("Incorrect argument type passed to Toy_getFilePathLiteral\n"); + return TOY_TO_NULL_LITERAL; + } + Toy_RefString* drivePath = Toy_copyRefString(TOY_AS_STRING(*drivePathLiteral)); //get the drive and path as a string (can't trust that pesky strtok - custom split) TODO: move this to refstring library int driveLength = 0; while (Toy_toCString(drivePath)[driveLength] != ':') { if (driveLength >= Toy_lengthRefString(drivePath)) { - interpreter->errorOutput("Incorrect drive path format given to getFilePathLiteral\n"); + interpreter->errorOutput("Incorrect drive path format given to Toy_getFilePathLiteral\n"); return TOY_TO_NULL_LITERAL; }