1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-27 17:00:27 +00:00

Check type when getting socket type

janet_get_sockettype expects a keyword but we're making it optional that
the call to the functions that use it with arity >=3 will be guaranteed
to have it as a keyword value! If it's not a keyword then it's the same
as NULL.
This commit is contained in:
llmII 2021-09-06 09:53:53 -05:00
parent 532dac1b95
commit 6ad016c587
No known key found for this signature in database
GPG Key ID: E3AD2E259F58A9A0

View File

@ -248,7 +248,9 @@ JANET_NO_RETURN static void janet_sched_accept(JanetStream *stream, JanetFunctio
/* Adress info */ /* Adress info */
static int janet_get_sockettype(Janet *argv, int32_t argc, int32_t n) { static int janet_get_sockettype(Janet *argv, int32_t argc, int32_t n) {
JanetKeyword stype = janet_optkeyword(argv, argc, n, NULL); JanetKeyword stype = NULL;
if(janet_checktype(argv[n], JANET_KEYWORD))
stype = janet_optkeyword(argv, argc, n, NULL);
int socktype = SOCK_DGRAM; int socktype = SOCK_DGRAM;
if ((NULL == stype) || !janet_cstrcmp(stype, "stream")) { if ((NULL == stype) || !janet_cstrcmp(stype, "stream")) {
socktype = SOCK_STREAM; socktype = SOCK_STREAM;