diff --git a/ccutil/unicharset.cpp b/ccutil/unicharset.cpp index 380c74101f..f36ac039de 100644 --- a/ccutil/unicharset.cpp +++ b/ccutil/unicharset.cpp @@ -1009,13 +1009,13 @@ int UNICHARSET::add_script(const char* script) { if (script_table_size_reserved == 0) { script_table_size_reserved = 8; script_table = new char*[script_table_size_reserved]; - } - if (script_table_size_used + 1 >= script_table_size_reserved) { - char** new_script_table = new char*[script_table_size_reserved * 2]; - memcpy(new_script_table, script_table, script_table_size_reserved * sizeof(char*)); + } else if (script_table_size_used >= script_table_size_reserved) { + assert(script_table_size_used == script_table_size_reserved); + script_table_size_reserved += script_table_size_reserved; + char** new_script_table = new char*[script_table_size_reserved]; + memcpy(new_script_table, script_table, script_table_size_used * sizeof(char*)); delete[] script_table; script_table = new_script_table; - script_table_size_reserved = 2 * script_table_size_reserved; } script_table[script_table_size_used] = new char[strlen(script) + 1]; strcpy(script_table[script_table_size_used], script);