Bugs in read_line leading to bad strings and in generic_search_all_buffers leading to using garbage results from read_line FIXED!

master
Allen Webster 2017-11-13 12:34:31 -05:00
parent ef33649221
commit 0f73cdecdb
2 changed files with 33 additions and 30 deletions

View File

@ -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;

View File

@ -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);
}
}