diff options
author | Alexander Barkov <bar@mariadb.org> | 2016-05-17 15:27:10 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.org> | 2016-05-17 15:27:10 +0400 |
commit | e7ff281d2e954f9ab7f08a3e1a425a3c59e8f796 (patch) | |
tree | e8e3903a609daef952785e28e5c876bafd52ba7b /sql/debug_sync.cc | |
parent | 7e66a24dfb381290d59786c36e1dc478ad365bd1 (diff) | |
download | mariadb-git-e7ff281d2e954f9ab7f08a3e1a425a3c59e8f796.tar.gz |
MDEV-6353 my_ismbchar() and my_mbcharlen() refactoring
Diffstat (limited to 'sql/debug_sync.cc')
-rw-r--r-- | sql/debug_sync.cc | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/sql/debug_sync.cc b/sql/debug_sync.cc index 8b3412eb732..b2a187b07cb 100644 --- a/sql/debug_sync.cc +++ b/sql/debug_sync.cc @@ -847,16 +847,16 @@ static bool debug_sync_set_action(THD *thd, st_debug_sync_action *action) to the string terminator ASCII NUL ('\0'). */ -static char *debug_sync_token(char **token_p, uint *token_length_p, char *ptr) +static char *debug_sync_token(char **token_p, uint *token_length_p, + char *ptr, char *ptrend) { DBUG_ASSERT(token_p); DBUG_ASSERT(token_length_p); DBUG_ASSERT(ptr); /* Skip leading space */ - while (my_isspace(system_charset_info, *ptr)) - ptr+= my_mbcharlen(system_charset_info, (uchar) *ptr); - + ptr+= system_charset_info->cset->scan(system_charset_info, + ptr, ptrend, MY_SEQ_SPACES); if (!*ptr) { ptr= NULL; @@ -867,8 +867,8 @@ static char *debug_sync_token(char **token_p, uint *token_length_p, char *ptr) *token_p= ptr; /* Find token end. */ - while (*ptr && !my_isspace(system_charset_info, *ptr)) - ptr+= my_mbcharlen(system_charset_info, (uchar) *ptr); + ptr+= system_charset_info->cset->scan(system_charset_info, + ptr, ptrend, MY_SEQ_NONSPACES); /* Get token length. */ *token_length_p= ptr - *token_p; @@ -876,8 +876,9 @@ static char *debug_sync_token(char **token_p, uint *token_length_p, char *ptr) /* If necessary, terminate token. */ if (*ptr) { + DBUG_ASSERT(ptr < ptrend); /* Get terminator character length. */ - uint mbspacelen= my_mbcharlen(system_charset_info, (uchar) *ptr); + uint mbspacelen= my_charlen_fix(system_charset_info, ptr, ptrend); /* Terminate token. */ *ptr= '\0'; @@ -886,8 +887,8 @@ static char *debug_sync_token(char **token_p, uint *token_length_p, char *ptr) ptr+= mbspacelen; /* Skip trailing space */ - while (my_isspace(system_charset_info, *ptr)) - ptr+= my_mbcharlen(system_charset_info, (uchar) *ptr); + ptr+= system_charset_info->cset->scan(system_charset_info, + ptr, ptrend, MY_SEQ_SPACES); } end: @@ -917,7 +918,8 @@ static char *debug_sync_token(char **token_p, uint *token_length_p, char *ptr) undefined in this case. */ -static char *debug_sync_number(ulong *number_p, char *actstrptr) +static char *debug_sync_number(ulong *number_p, char *actstrptr, + char *actstrend) { char *ptr; char *ept; @@ -927,7 +929,7 @@ static char *debug_sync_number(ulong *number_p, char *actstrptr) DBUG_ASSERT(actstrptr); /* Get token from string. */ - if (!(ptr= debug_sync_token(&token, &token_length, actstrptr))) + if (!(ptr= debug_sync_token(&token, &token_length, actstrptr, actstrend))) goto end; *number_p= strtoul(token, &ept, 10); @@ -971,7 +973,7 @@ static char *debug_sync_number(ulong *number_p, char *actstrptr) for the string. */ -static bool debug_sync_eval_action(THD *thd, char *action_str) +static bool debug_sync_eval_action(THD *thd, char *action_str, char *action_end) { st_debug_sync_action *action= NULL; const char *errmsg; @@ -986,7 +988,7 @@ static bool debug_sync_eval_action(THD *thd, char *action_str) /* Get debug sync point name. Or a special command. */ - if (!(ptr= debug_sync_token(&token, &token_length, action_str))) + if (!(ptr= debug_sync_token(&token, &token_length, action_str, action_end))) { errmsg= "Missing synchronization point name"; goto err; @@ -1009,7 +1011,7 @@ static bool debug_sync_eval_action(THD *thd, char *action_str) /* Get kind of action to be taken at sync point. */ - if (!(ptr= debug_sync_token(&token, &token_length, ptr))) + if (!(ptr= debug_sync_token(&token, &token_length, ptr, action_end))) { /* No action present. Try special commands. Token unchanged. */ @@ -1090,7 +1092,7 @@ static bool debug_sync_eval_action(THD *thd, char *action_str) if (!my_strcasecmp(system_charset_info, token, "SIGNAL")) { /* It is SIGNAL. Signal name must follow. */ - if (!(ptr= debug_sync_token(&token, &token_length, ptr))) + if (!(ptr= debug_sync_token(&token, &token_length, ptr, action_end))) { errmsg= "Missing signal name after action SIGNAL"; goto err; @@ -1108,7 +1110,7 @@ static bool debug_sync_eval_action(THD *thd, char *action_str) action->execute= 1; /* Get next token. If none follows, set action. */ - if (!(ptr= debug_sync_token(&token, &token_length, ptr))) + if (!(ptr= debug_sync_token(&token, &token_length, ptr, action_end))) goto set_action; } @@ -1118,7 +1120,7 @@ static bool debug_sync_eval_action(THD *thd, char *action_str) if (!my_strcasecmp(system_charset_info, token, "WAIT_FOR")) { /* It is WAIT_FOR. Wait_for signal name must follow. */ - if (!(ptr= debug_sync_token(&token, &token_length, ptr))) + if (!(ptr= debug_sync_token(&token, &token_length, ptr, action_end))) { errmsg= "Missing signal name after action WAIT_FOR"; goto err; @@ -1137,7 +1139,7 @@ static bool debug_sync_eval_action(THD *thd, char *action_str) action->timeout= opt_debug_sync_timeout; /* Get next token. If none follows, set action. */ - if (!(ptr= debug_sync_token(&token, &token_length, ptr))) + if (!(ptr= debug_sync_token(&token, &token_length, ptr, action_end))) goto set_action; /* @@ -1146,14 +1148,14 @@ static bool debug_sync_eval_action(THD *thd, char *action_str) if (!my_strcasecmp(system_charset_info, token, "TIMEOUT")) { /* It is TIMEOUT. Number must follow. */ - if (!(ptr= debug_sync_number(&action->timeout, ptr))) + if (!(ptr= debug_sync_number(&action->timeout, ptr, action_end))) { errmsg= "Missing valid number after TIMEOUT"; goto err; } /* Get next token. If none follows, set action. */ - if (!(ptr= debug_sync_token(&token, &token_length, ptr))) + if (!(ptr= debug_sync_token(&token, &token_length, ptr, action_end))) goto set_action; } } @@ -1174,14 +1176,14 @@ static bool debug_sync_eval_action(THD *thd, char *action_str) } /* Number must follow. */ - if (!(ptr= debug_sync_number(&action->execute, ptr))) + if (!(ptr= debug_sync_number(&action->execute, ptr, action_end))) { errmsg= "Missing valid number after EXECUTE"; goto err; } /* Get next token. If none follows, set action. */ - if (!(ptr= debug_sync_token(&token, &token_length, ptr))) + if (!(ptr= debug_sync_token(&token, &token_length, ptr, action_end))) goto set_action; } @@ -1191,14 +1193,14 @@ static bool debug_sync_eval_action(THD *thd, char *action_str) if (!my_strcasecmp(system_charset_info, token, "HIT_LIMIT")) { /* Number must follow. */ - if (!(ptr= debug_sync_number(&action->hit_limit, ptr))) + if (!(ptr= debug_sync_number(&action->hit_limit, ptr, action_end))) { errmsg= "Missing valid number after HIT_LIMIT"; goto err; } /* Get next token. If none follows, set action. */ - if (!(ptr= debug_sync_token(&token, &token_length, ptr))) + if (!(ptr= debug_sync_token(&token, &token_length, ptr, action_end))) goto set_action; } @@ -1246,7 +1248,7 @@ static bool debug_sync_eval_action(THD *thd, char *action_str) terminators in the string. So we need to take a copy here. */ -bool debug_sync_update(THD *thd, char *val_str) +bool debug_sync_update(THD *thd, char *val_str, size_t len) { DBUG_ENTER("debug_sync_update"); DBUG_PRINT("debug_sync", ("set action: '%s'", val_str)); @@ -1255,8 +1257,9 @@ bool debug_sync_update(THD *thd, char *val_str) debug_sync_eval_action() places '\0' in the string, which itself must be '\0' terminated. */ + DBUG_ASSERT(val_str[len] == '\0'); DBUG_RETURN(opt_debug_sync_timeout ? - debug_sync_eval_action(thd, val_str) : + debug_sync_eval_action(thd, val_str, val_str + len) : FALSE); } @@ -1592,7 +1595,7 @@ bool debug_sync_set_action(THD *thd, const char *action_str, size_t len) DBUG_ASSERT(action_str); value= strmake_root(thd->mem_root, action_str, len); - rc= debug_sync_eval_action(thd, value); + rc= debug_sync_eval_action(thd, value, value + len); DBUG_RETURN(rc); } |