diff --git a/src/pk_core.c b/src/pk_core.c index 40e34b1..f06e8c3 100644 --- a/src/pk_core.c +++ b/src/pk_core.c @@ -6,6 +6,7 @@ #include "pk_core.h" #include +#include #include #include @@ -31,6 +32,9 @@ static const char* DOCSTRING(fn) = docstring; \ static void fn(PKVM* vm) +// Checks if a number is a byte +#define IS_NUM_BYTE(num) ((CHAR_MIN <= (num)) && ((num) <= CHAR_MAX)) + /*****************************************************************************/ /* CORE PUBLIC API */ /*****************************************************************************/ @@ -613,7 +617,9 @@ DEF(coreStrChr, int64_t num; if (!validateInteger(vm, ARG(1), &num, "Argument 1")) return; - // TODO: validate num is a byte. + if (!IS_NUM_BYTE(num)) { + RET_ERR(newString(vm, "The number is not in a byte range.")); + } char c = (char)num; RET(VAR_OBJ(newStringLength(vm, &c, 1)));