From ce3c06d908ebf4eb1814eab1ca40efb189d8ed25 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sat, 12 May 2018 00:20:37 -0700 Subject: [PATCH] fixed auto indent on save bug caused by reorganizing custom layer, fixed lexer crash bug --- 4coder_default_hooks.cpp | 5 ++--- 4coder_lib/4cpp_lexer.h | 46 +++++++++++++++++++++------------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/4coder_default_hooks.cpp b/4coder_default_hooks.cpp index b05f931c..d2b84997 100644 --- a/4coder_default_hooks.cpp +++ b/4coder_default_hooks.cpp @@ -320,14 +320,13 @@ OPEN_FILE_HOOK_SIG(default_file_save){ Buffer_Summary buffer = get_buffer(app, buffer_id, AccessAll); Assert(buffer.exists); -#if defined(FCODER_AUTO_INDENT_CPP) int32_t is_virtual = 0; - if (automatically_indent_text_on_save && buffer_get_setting(app, &buffer, BufferSetting_VirtualWhitespace, &is_virtual)){ + if (global_config.automatically_indent_text_on_save && + buffer_get_setting(app, &buffer, BufferSetting_VirtualWhitespace, &is_virtual)){ if (is_virtual){ buffer_auto_indent(app, &global_part, &buffer, 0, buffer.size, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens); } } -#endif // no meaning for return return(0); diff --git a/4coder_lib/4cpp_lexer.h b/4coder_lib/4cpp_lexer.h index 204eeb3a..4e36d424 100644 --- a/4coder_lib/4cpp_lexer.h +++ b/4coder_lib/4cpp_lexer.h @@ -283,28 +283,30 @@ cpp__table_match(Cpp_Keyword_Table *table, char *s, u32_4tech s_len, u32_4tech * b32_4tech result = false; u32_4tech max = table->max; - u32_4tech first_index = hash % max; - u32_4tech index = first_index; - for (;;){ - u64_4tech *keyword_ptr = keywords + index; - if (*keyword_ptr == 0){ - break; - } - - u32_4tech *str_len = (u32_4tech*)(*keyword_ptr + base); - char *str = (char*)(str_len + 2); - if (cpp__match(str, *str_len, s, s_len)){ - *item_ptr_out = (u32_4tech*)(*keyword_ptr + base); - result = true; - break; - } - - ++index; - if (index >= max){ - index = 0; - } - if (index == first_index){ - break; + if (max > 0){ + u32_4tech first_index = hash % max; + u32_4tech index = first_index; + for (;;){ + u64_4tech *keyword_ptr = keywords + index; + if (*keyword_ptr == 0){ + break; + } + + u32_4tech *str_len = (u32_4tech*)(*keyword_ptr + base); + char *str = (char*)(str_len + 2); + if (cpp__match(str, *str_len, s, s_len)){ + *item_ptr_out = (u32_4tech*)(*keyword_ptr + base); + result = true; + break; + } + + ++index; + if (index >= max){ + index = 0; + } + if (index == first_index){ + break; + } } }