diff options
| author | 2023-03-23 18:52:37 -0400 | |
|---|---|---|
| committer | 2023-03-23 18:52:37 -0400 | |
| commit | d1b9266199a92038271de8b7829e450ff67adba8 (patch) | |
| tree | 6ec785a842f6697234b45860474b6f1faeb17a21 | |
| parent | native: fix nasty bug (diff) | |
Revert "native: NULL-terminate all struct[]s"
This reverts commit 5ebde8722822ddac5b79755dbeb4c404f1c879fa.
| -rw-r--r-- | src/enums.c | 4 | ||||
| -rw-r--r-- | src/errors.c | 6 | ||||
| -rw-r--r-- | src/getinfo.c | 5 | ||||
| -rw-r--r-- | src/main.c | 1 | ||||
| -rw-r--r-- | src/setopt.c | 5 |
5 files changed, 9 insertions, 12 deletions
diff --git a/src/enums.c b/src/enums.c index bd975bc..1228f63 100644 --- a/src/enums.c +++ b/src/enums.c @@ -169,11 +169,11 @@ static const struct jurl_enum jurl_enums[] = { {CURLOPT_SSH_AUTH_TYPES, CURLSSH_AUTH_KEYBOARD, "ssh-auth/keyboard"}, {CURLOPT_SSH_AUTH_TYPES, CURLSSH_AUTH_AGENT, "ssh-auth/agent"}, {CURLOPT_SSH_AUTH_TYPES, CURLSSH_AUTH_ANY, "ssh-auth/any"}, - {0, 0, NULL}, }; +#define jurl_enum_size (sizeof(jurl_enums) / sizeof(struct jurl_enum)) static long get_eq(CURLoption opt, JanetKeyword kw) { - for (size_t i = 0; jurl_enums[i].keyword; i++) { + for (size_t i = 0; i < jurl_enum_size; i++) { if (jurl_enums[i].opt == opt && !strcmp(jurl_enums[i].keyword, (const char*)kw)) { return jurl_enums[i].value; } diff --git a/src/errors.c b/src/errors.c index 57097dc..94219fe 100644 --- a/src/errors.c +++ b/src/errors.c @@ -105,12 +105,12 @@ static const struct jurl_error jurl_errors[] = { {CURLE_PROXY, "error/proxy"}, {CURLE_SSL_CLIENTCERT, "error/ssl-clientcert"}, {CURLE_UNRECOVERABLE_POLL, "error/unrecoverable-poll"}, - {0, NULL}, }; +#define jurl_error_size (sizeof(jurl_errors) / sizeof(struct jurl_error)) // translate a CURLcode return code into a keyword Janet jurl_geterror(CURLcode code) { - for (size_t i = 0; jurl_errors[i].keyword; i++) { + for (size_t i = 0; i < jurl_error_size; i++) { if (jurl_errors[i].code == code) { return janet_ckeywordv(jurl_errors[i].keyword); } @@ -125,7 +125,7 @@ JANET_CFUN(jurl_strerror) { Janet arg = argv[0]; switch (janet_checktypes(arg, JANET_TFLAG_KEYWORD | JANET_TFLAG_NUMBER)) { case JANET_TFLAG_KEYWORD: - for (size_t i = 0; jurl_errors[i].keyword; i++) { + for (size_t i = 0; i < jurl_error_size; i++) { if (janet_keyeq(arg, jurl_errors[i].keyword)) { code = jurl_errors[i].code; break; diff --git a/src/getinfo.c b/src/getinfo.c index bf058f8..95fd6be 100644 --- a/src/getinfo.c +++ b/src/getinfo.c @@ -86,7 +86,6 @@ static const struct jurl_opt jurl_opts[] = { {CURLINFO_RTSP_CSEQ_RECV, "rtsp-cseq-recv", JURL_PARAMTYPE_LONG}, // SKIP: protocol: deprecated for scheme {CURLINFO_SCHEME, "scheme", JURL_PARAMTYPE_STRING}, - {0, NULL, 0}, }; JANET_CFUN(jurl_getinfo) { @@ -96,7 +95,7 @@ JANET_CFUN(jurl_getinfo) { const struct jurl_opt *opt; Janet jopt = argv[1]; - for (size_t i = 0; jurl_opts[i].keyword; i++) { + for (size_t i = 0; i < sizeof(jurl_opts) / sizeof(struct jurl_opt); i++) { if(janet_keyeq(jopt, jurl_opts[i].keyword)) { opt = &jurl_opts[i]; break; @@ -104,7 +103,7 @@ JANET_CFUN(jurl_getinfo) { } if (!opt) { int num = janet_getinteger(argv, 1); - for (size_t i = 0; jurl_opts[i].keyword; i++) { + for (size_t i = 0; i < sizeof(jurl_opts) / sizeof(struct jurl_opt); i++) { if (num == jurl_opts[i].info) { opt = &jurl_opts[i]; break; @@ -152,7 +152,6 @@ static const JanetRegExt cfuns[] = { // jurl_setopt.c JANET_REG("setopt", jurl_setopt), - JANET_REG_END, }; JANET_MODULE_ENTRY(JanetTable *env) { diff --git a/src/setopt.c b/src/setopt.c index a32c8a8..e000731 100644 --- a/src/setopt.c +++ b/src/setopt.c @@ -351,7 +351,6 @@ static const struct jurl_opt jurl_opts[] = { // * telnet options {CURLOPT_TELNETOPTIONS, "telnetoptions", JURL_PARAMTYPE_SLIST}, - {0, NULL, 0}, }; JANET_CFUN(jurl_setopt) { @@ -360,7 +359,7 @@ JANET_CFUN(jurl_setopt) { const struct jurl_opt *opt; Janet jopt = argv[1]; - for (size_t i = 0; jurl_opts[i].keyword; i++) { + for (size_t i = 0; i < sizeof(jurl_opts) / sizeof(struct jurl_opt); i++) { if (janet_keyeq(jopt, jurl_opts[i].keyword)) { opt = &jurl_opts[i]; break; @@ -368,7 +367,7 @@ JANET_CFUN(jurl_setopt) { } if (!opt) { int num = janet_getinteger(argv, 1); - for (size_t i = 0; jurl_opts[i].keyword; i++) { + for (size_t i = 0; i < sizeof(jurl_opts) / sizeof(struct jurl_opt); i++) { if (num == jurl_opts[i].opt) { opt = &jurl_opts[i]; break; |
