summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2016-05-17 15:27:10 +0400
committerAlexander Barkov <bar@mariadb.org>2016-05-17 15:27:10 +0400
commite7ff281d2e954f9ab7f08a3e1a425a3c59e8f796 (patch)
treee8e3903a609daef952785e28e5c876bafd52ba7b /sql
parent7e66a24dfb381290d59786c36e1dc478ad365bd1 (diff)
downloadmariadb-git-e7ff281d2e954f9ab7f08a3e1a425a3c59e8f796.tar.gz
MDEV-6353 my_ismbchar() and my_mbcharlen() refactoring
Diffstat (limited to 'sql')
-rw-r--r--sql/create_options.cc2
-rw-r--r--sql/debug_sync.cc57
-rw-r--r--sql/debug_sync.h3
-rw-r--r--sql/sql_class.cc2
-rw-r--r--sql/sys_vars.ic16
5 files changed, 46 insertions, 34 deletions
diff --git a/sql/create_options.cc b/sql/create_options.cc
index 66515be05b8..3011c4b2d7e 100644
--- a/sql/create_options.cc
+++ b/sql/create_options.cc
@@ -184,7 +184,7 @@ static bool set_one_value(ha_create_table_option *opt,
{
for (end=start;
*end && *end != ',';
- end+= my_mbcharlen(system_charset_info, *end)) /* no-op */;
+ end++) /* no-op */;
if (!my_strnncoll(system_charset_info,
(uchar*)start, end-start,
(uchar*)value->str, value->length))
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);
}
diff --git a/sql/debug_sync.h b/sql/debug_sync.h
index bf1b3167dbc..339a21139b1 100644
--- a/sql/debug_sync.h
+++ b/sql/debug_sync.h
@@ -45,6 +45,9 @@ extern void debug_sync_init_thread(THD *thd);
extern void debug_sync_end_thread(THD *thd);
extern bool debug_sync_set_action(THD *thd, const char *action_str, size_t len);
+extern bool debug_sync_update(THD *thd, char *val_str, size_t len);
+extern uchar *debug_sync_value_ptr(THD *thd);
+
#endif /* defined(ENABLED_DEBUG_SYNC) */
#endif /* DEBUG_SYNC_INCLUDED */
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index b1217cb1f9f..be950627f08 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -3235,7 +3235,7 @@ int select_export::send_data(List<Item> &items)
if ((NEED_ESCAPING(*pos) ||
(check_second_byte &&
- my_mbcharlen(character_set_client, (uchar) *pos) == 2 &&
+ ((uchar) *pos) > 0x7F /* a potential MB2HEAD */ &&
pos + 1 < end &&
NEED_ESCAPING(pos[1]))) &&
/*
diff --git a/sql/sys_vars.ic b/sql/sys_vars.ic
index 373f5834838..2488e804310 100644
--- a/sql/sys_vars.ic
+++ b/sql/sys_vars.ic
@@ -1434,6 +1434,9 @@ public:
};
#if defined(ENABLED_DEBUG_SYNC)
+
+#include "debug_sync.h"
+
/**
The class for @@debug_sync session-only variable
*/
@@ -1462,15 +1465,19 @@ public:
String str(buff, sizeof(buff), system_charset_info), *res;
if (!(res=var->value->val_str(&str)))
- var->save_result.string_value.str= const_cast<char*>("");
+ var->save_result.string_value= empty_lex_str;
else
- var->save_result.string_value.str= thd->strmake(res->ptr(), res->length());
+ {
+ if (!thd->make_lex_string(&var->save_result.string_value,
+ res->ptr(), res->length()))
+ return true;
+ }
return false;
}
bool session_update(THD *thd, set_var *var)
{
- extern bool debug_sync_update(THD *thd, char *val_str);
- return debug_sync_update(thd, var->save_result.string_value.str);
+ return debug_sync_update(thd, var->save_result.string_value.str,
+ var->save_result.string_value.length);
}
bool global_update(THD *thd, set_var *var)
{
@@ -1488,7 +1495,6 @@ public:
}
uchar *session_value_ptr(THD *thd, const LEX_STRING *base)
{
- extern uchar *debug_sync_value_ptr(THD *thd);
return debug_sync_value_ptr(thd);
}
uchar *global_value_ptr(THD *thd, const LEX_STRING *base)