10000 frigging tokto strto stuff. · memcached/memcached@c25675a · GitHub
[go: up one dir, main page]

Skip to content

Commit c25675a

Browse files
committed
frigging tokto strto stuff.
1 parent 052de9d commit c25675a

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

proto_parser.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,15 @@ int process_request(mcp_parser_t *pr, const char *command, size_t cmdlen) {
332332
* PARSER UTIL CODE
333333
*/
334334

335+
// TODO:
336+
// - the safe_strto calls in here are still "string-y" - they're going to
337+
// parse until a space or newline. This is perfectly safe for any time we're
338+
// in this code; since we can't get here without a \n or a space (ie;
339+
// non-digit)
340+
// - I'm not converting these to tokto*'s right now, because what they're
341+
// pulling the flag while in a loop. So we need yet another interface (or
342+
// refactor of existing interface). This code is safe, just not consistent.
343+
335344
int mc_prcmp(mcp_parser_t *pr, int token, const char *s) {
336345
int len = 0;
337346
const char *t = mcmc_token_get(pr->request, &pr->tok, token, &len);
@@ -730,8 +739,6 @@ item *process_update_cmd_start(LIBEVENT_THREAD *t, mcp_parser_t *pr, mc_resp *re
730739
return NULL;
731740
}
732741

733-
// TODO: convert to mcmc_token_etc which do not use strtol underneath.
734-
// safe_strtoflags is an alias based on large client flags :(
735742
if (! (safe_strtoflags(&pr->request[pr->tok.tokens[2]], &flags)
736743
&& safe_strtol(&pr->request[pr->tok.tokens[3]], &exptime_int))) {
737744
pout_string(resp, "CLIENT_ERROR bad command line format");

proto_text.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ static void process_get_command(conn *c, LIBEVENT_THREAD *t, mcp_parser_t *pr, p
435435

436436
if (should_touch) {
437437
int32_t exptime_int = 0;
438-
if (!safe_strtol(&pr->request[pr->tok.tokens[1]], &exptime_int)) {
438+
if (!mc_tokto32(pr, 1, &exptime_int)) {
439439
out_string(c, "CLIENT_ERROR invalid exptime argument");
440440
return;
441441
}
@@ -893,19 +893,15 @@ static void process_slabs_automove_command(conn *c, mcp_parser_t *pr) {
893893

894894
const char *subcmd = mcmc_token_get(pr->request, &pr->tok, 2, &len);
895895
if (strncmp(subcmd, "ratio", len) == 0) {
896-
int vlen = 0;
897-
const char *val = mcmc_token_get(pr->request, &pr->tok, 3, &vlen);
898-
if (ntokens < 4 || !safe_strtod(val, &ratio)) {
896+
if (ntokens < 4 || !mc_toktod(pr, 3, &ratio)) {
899897
out_string(c, "ERROR");
900898
return;
901899
}
902900
// TODO: settings needs an overhaul... no locks/etc.
903901
settings.slab_automove_ratio = ratio;
904902
settings.slab_automove_version++;
905903
} else if (strncmp(subcmd, "freeratio", len) == 0) {
906-
int vlen = 0;
907-
const char *val = mcmc_token_get(pr->request, &pr->tok, 3, &vlen);
908-
if (ntokens < 4 || !safe_strtod(val, &ratio)) {
904+
if (ntokens < 4 || !mc_toktod(pr, 3, &ratio)) {
909905
out_string(c, "ERROR");
910906
return;
911907
}

0 commit comments

Comments
 (0)
0