From 6b9375ed66f68ef20e1b39028e3a5b61653fd15c Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Fri, 4 Feb 2022 18:05:28 -0500 Subject: [PATCH] =?UTF-8?q?Check=20range=20for=20=E2=80=A2bit.=5Fcast=20ch?= =?UTF-8?q?aracter=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/sysfn.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index 404cc50b..198e48f4 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -872,10 +872,11 @@ static CastType getCastType(B e, B v) { s = o2s(GetU(e,0)); u32 t = o2c(GetU(e,1)); c = t=='c'; - if (c||t=='n'); // n for generic number - else if (t=='f') { if (s!=64) thrM("•bit._cast: type f only supports width 64"); } + if (t=='n'); // generic number + else if (c ) { if (s<8||s>32) thrM("•bit._cast: unsupported character width"); } else if (t=='i') { if (s<8||s>32) thrM("•bit._cast: unsupported integer width"); } else if (t=='u') { if ( s>32) thrM("•bit._cast: unsupported integer width"); } + else if (t=='f') { if (s!=64) thrM("•bit._cast: type f only supports width 64"); } else thrM("•bit._cast: type descriptor in 𝕗 must be one of \"iufnc\""); } return (CastType) { s, c };