From 0f73cdecdb05c004953182eb565af0a0b535101f Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Mon, 13 Nov 2017 12:34:31 -0500 Subject: [PATCH] Bugs in read_line leading to bad strings and in generic_search_all_buffers leading to using garbage results from read_line FIXED! --- 4coder_helper/4coder_long_seek.h | 6 ++-- 4coder_search.cpp | 57 ++++++++++++++++---------------- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/4coder_helper/4coder_long_seek.h b/4coder_helper/4coder_long_seek.h index 59e024a8..65a1a8a5 100644 --- a/4coder_helper/4coder_long_seek.h +++ b/4coder_helper/4coder_long_seek.h @@ -950,8 +950,10 @@ read_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, int32 if (begin.line == line){ if (0 <= begin.pos && begin.pos <= end.pos && end.pos <= buffer->size){ int32_t size = (end.pos - begin.pos); - *str = make_string(push_array(part, char, size+1), size+1); - if (str->str){ + int32_t alloc_size = size + 1; + char *memory = push_array(part, char, alloc_size); + if (memory != 0){ + *str = make_string(memory, 0, alloc_size); success = true; buffer_read_range(app, buffer, begin.pos, end.pos, str->str); str->size = size; diff --git a/4coder_search.cpp b/4coder_search.cpp index be46d78b..7ee96382 100644 --- a/4coder_search.cpp +++ b/4coder_search.cpp @@ -596,38 +596,39 @@ generic_search_all_buffers(Application_Links *app, General_Memory *general, Part Temp_Memory line_temp = begin_temp_memory(&line_part); String line_str = {0}; - read_line(app, &line_part, &match.buffer, word_pos.line, &line_str); - line_str = skip_chop_whitespace(line_str); - - int32_t str_len = file_len + 1 + line_num_len + 1 + column_num_len + 1 + 1 + line_str.size + 1; - - char *spare = push_array(part, char, str_len); - - if (spare == 0){ - buffer_replace_range(app, &search_buffer, size, size, str, part_size); - size += part_size; + if (read_line(app, &line_part, &match.buffer, word_pos.line, &line_str)){ + line_str = skip_chop_whitespace(line_str); - end_temp_memory(temp); - temp = begin_temp_memory(part); + int32_t str_len = file_len + 1 + line_num_len + 1 + column_num_len + 1 + 1 + line_str.size + 1; - part_size = 0; - spare = push_array(part, char, str_len); + char *spare = push_array(part, char, str_len); + + if (spare == 0){ + buffer_replace_range(app, &search_buffer, size, size, str, part_size); + size += part_size; + + end_temp_memory(temp); + temp = begin_temp_memory(part); + + part_size = 0; + spare = push_array(part, char, str_len); + } + + part_size += str_len; + + String out_line = make_string_cap(spare, 0, str_len); + append_ss(&out_line, make_string(file_name, file_len)); + append_s_char(&out_line, ':'); + append_int_to_str(&out_line, word_pos.line); + append_s_char(&out_line, ':'); + append_int_to_str(&out_line, word_pos.character); + append_s_char(&out_line, ':'); + append_s_char(&out_line, ' '); + append_ss(&out_line, line_str); + append_s_char(&out_line, '\n'); + Assert(out_line.size == str_len); } - part_size += str_len; - - String out_line = make_string_cap(spare, 0, str_len); - append_ss(&out_line, make_string(file_name, file_len)); - append_s_char(&out_line, ':'); - append_int_to_str(&out_line, word_pos.line); - append_s_char(&out_line, ':'); - append_int_to_str(&out_line, word_pos.character); - append_s_char(&out_line, ':'); - append_s_char(&out_line, ' '); - append_ss(&out_line, line_str); - append_s_char(&out_line, '\n'); - Assert(out_line.size == str_len); - end_temp_memory(line_temp); } }