Skip to content

Commit 8528eac

Browse files
committed
MDEV-31954 Cleanup in check_table_name() and check_db_name()
- Renaming the parameter `check_for_path_char` to a more self-descriptive `disallow_path_chars` - Renaming the variable `name_length` in check_table_name() to a more self-descriptive `char_length`. - Fix the `while` loop in check_table_name() into a `for` loop and replace multiple {{char_length++}} (the former {{name_length++}}) statements to a signle increment statement in the `for` loop header.
1 parent 39bafad commit 8528eac

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

sql/table.cc

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5208,9 +5208,9 @@ bool check_db_name(LEX_STRING *org_name)
52085208
{
52095209
char *name= org_name->str;
52105210
size_t name_length= org_name->length;
5211-
bool check_for_path_chars;
5211+
bool disallow_path_chars;
52125212

5213-
if ((check_for_path_chars= check_mysql50_prefix(name)))
5213+
if ((disallow_path_chars= check_mysql50_prefix(name)))
52145214
{
52155215
name+= MYSQL50_TABLE_NAME_PREFIX_LENGTH;
52165216
name_length-= MYSQL50_TABLE_NAME_PREFIX_LENGTH;
@@ -5222,13 +5222,13 @@ bool check_db_name(LEX_STRING *org_name)
52225222
if (lower_case_table_names == 1 && name != any_db.str)
52235223
{
52245224
org_name->length= name_length= my_casedn_str(files_charset_info, name);
5225-
if (check_for_path_chars)
5225+
if (disallow_path_chars)
52265226
org_name->length+= MYSQL50_TABLE_NAME_PREFIX_LENGTH;
52275227
}
52285228
if (db_name_is_in_ignore_db_dirs_list(name))
52295229
return 1;
52305230

5231-
return check_table_name(name, name_length, check_for_path_chars);
5231+
return check_table_name(name, name_length, disallow_path_chars);
52325232
}
52335233

52345234

@@ -5238,14 +5238,14 @@ bool check_db_name(LEX_STRING *org_name)
52385238
returns 1 on error
52395239
*/
52405240

5241-
bool check_table_name(const char *name, size_t length, bool check_for_path_chars)
5241+
bool check_table_name(const char *name, size_t length, bool disallow_path_chars)
52425242
{
52435243
// name length in symbols
5244-
size_t name_length= 0;
5244+
size_t char_length= 0;
52455245
const char *end= name+length;
52465246

5247-
if (!check_for_path_chars &&
5248-
(check_for_path_chars= check_mysql50_prefix(name)))
5247+
if (!disallow_path_chars &&
5248+
(disallow_path_chars= check_mysql50_prefix(name)))
52495249
{
52505250
name+= MYSQL50_TABLE_NAME_PREFIX_LENGTH;
52515251
length-= MYSQL50_TABLE_NAME_PREFIX_LENGTH;
@@ -5260,7 +5260,7 @@ bool check_table_name(const char *name, size_t length, bool check_for_path_chars
52605260
return 1;
52615261
#endif
52625262

5263-
while (name != end)
5263+
for ( ; name != end ; char_length++)
52645264
{
52655265
#if defined(USE_MB) && defined(USE_MB_IDENT)
52665266
last_char_is_space= my_isspace(system_charset_info, *name);
@@ -5270,12 +5270,11 @@ bool check_table_name(const char *name, size_t length, bool check_for_path_chars
52705270
if (len)
52715271
{
52725272
name+= len;
5273-
name_length++;
52745273
continue;
52755274
}
52765275
}
52775276
#endif
5278-
if (check_for_path_chars &&
5277+
if (disallow_path_chars &&
52795278
(*name == '/' || *name == '\\' || *name == '~' || *name == FN_EXTCHAR))
52805279
return 1;
52815280
/*
@@ -5294,10 +5293,9 @@ bool check_table_name(const char *name, size_t length, bool check_for_path_chars
52945293
if (*name == 0x00)
52955294
return 1;
52965295
name++;
5297-
name_length++;
52985296
}
52995297
#if defined(USE_MB) && defined(USE_MB_IDENT)
5300-
return last_char_is_space || (name_length > NAME_CHAR_LEN);
5298+
return last_char_is_space || (char_length > NAME_CHAR_LEN);
53015299
#else
53025300
return FALSE;
53035301
#endif

0 commit comments

Comments
 (0)