summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-03-03 20:27:53 +0100
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-03-03 20:27:53 +0100
commite49f9f584612700f322916d03b6bcc91ddb136ec (patch)
tree1859299fc87eb902516ebc5dbb2320f3d54ecd18 /src
parent7e0a7cea406d4dd4733dfa834ac7c41ce848e658 (diff)
fix use after free
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp8
-rw-r--r--src/main_windows.cpp10
-rw-r--r--src/search.cpp14
-rw-r--r--src/search.h2
4 files changed, 16 insertions, 18 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 16b46d1..687bbab 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -117,9 +117,9 @@ static int _ts_create_menu() {
}
void ts_init() {
- snprintf(path_buffer, MAX_INPUT_LENGTH, "%s", "C:\\Users\\aldri\\Desktop\\Vault\\Projects\\test");
+ snprintf(path_buffer, MAX_INPUT_LENGTH, "%s", "C:\\Users\\aldri\\Desktop\\Vault\\Projects\\allegro5\\build\\tests");
snprintf(filter_buffer, MAX_INPUT_LENGTH, "%s", "*.h");
- snprintf(query_buffer, MAX_INPUT_LENGTH, "%s", "あいうえお");
+ snprintf(query_buffer, MAX_INPUT_LENGTH, "%s", "test");
}
int _tb_query_input_cb(ImGuiInputTextCallbackData* data) {
@@ -236,9 +236,9 @@ void ts_create_gui(int window_w, int window_h) {
ImGui::TableNextColumn();
ImGui::Text("%.*s", file->word_match_offset, file->line_info);
- ImGui::SameLine();
+ ImGui::SameLine(0.0f, 0.0f);
ImGui::TextColored({255,0,0,255}, "%.*s", file->word_match_length, file->line_info + file->word_match_offset);
- ImGui::SameLine();
+ ImGui::SameLine(0.0f, 0.0f);
ImGui::TextUnformatted(file->line_info + file->word_match_offset + file->word_match_length);
ImGui::TableNextColumn();
diff --git a/src/main_windows.cpp b/src/main_windows.cpp
index 9930b46..d985416 100644
--- a/src/main_windows.cpp
+++ b/src/main_windows.cpp
@@ -317,13 +317,13 @@ void ts_platform_list_files_block(ts_search_result* result, wchar_t* start_dir)
wcscat(complete_file_path, L"\\");
wcscat(complete_file_path, name);
- ts_found_file f;
- f.path = (utf8_int8_t*)malloc(MAX_INPUT_LENGTH);
- f.match_count = 0;
- WideCharToMultiByte(CP_UTF8,0,complete_file_path,-1,(LPSTR)f.path,MAX_INPUT_LENGTH, NULL, NULL);
+ ts_found_file* f = (ts_found_file*)malloc(MAX_INPUT_LENGTH);
+ f->path = (utf8_int8_t*)malloc(MAX_INPUT_LENGTH);
+ f->match_count = 0;
+ WideCharToMultiByte(CP_UTF8,0,complete_file_path,-1,(LPSTR)f->path,MAX_INPUT_LENGTH, NULL, NULL);
ts_mutex_lock(&result->files.mutex);
- ts_array_push_size(&result->files, &f, sizeof(ts_found_file));
+ ts_array_push_size(&result->files, &f, sizeof(ts_found_file*));
ts_mutex_unlock(&result->files.mutex);
}
diff --git a/src/search.cpp b/src/search.cpp
index 76d46f3..76d7b92 100644
--- a/src/search.cpp
+++ b/src/search.cpp
@@ -209,13 +209,12 @@ bool ts_string_contains(char *text_to_search, utf8_int8_t *text_to_find, ts_arra
// text to find has reached 0byte, word has been found
if (text_to_find_ch == 0)
{
- word_offset_val -= utf8codepointsize(text_to_search_ch); // first codepoint was also added..
done:
if (save_info)
{
ts_text_match new_match;
new_match.line_nr = line_nr_val;
- new_match.word_offset = word_offset_val;
+ new_match.word_offset = word_offset_val - utf8codepointsize(text_to_search_ch); // first codepoint was also added..
new_match.word_match_len = word_match_len_val;
new_match.line_start = line_start_ptr;
new_match.line_info = 0;
@@ -267,17 +266,16 @@ static void _ts_search_file(ts_found_file *ref, ts_file_content content, ts_sear
file_match.word_match_offset = text_pad_lr;
}
int total_len = text_pad_lr + search_len + text_pad_lr;
-
snprintf(file_match.line_info, MAX_INPUT_LENGTH, "%.*s", total_len, m->line_start);
utf8_int32_t ch;
utf8_int8_t* iter = file_match.line_info;
while ((iter = utf8codepoint(iter, &ch)) && ch)
{
- if (ch == '\n') iter[0] = ' ';
- if (ch == '\t') iter[0] = ' ';
- if (ch == '\r') iter[0] = ' ';
- if (ch == '\x0B') iter[0] = ' ';
+ if (ch == '\n') iter[-1] = ' ';
+ if (ch == '\t') iter[-1] = ' ';
+ if (ch == '\r') iter[-1] = ' ';
+ if (ch == '\x0B') iter[-1] = ' ';
}
ts_array_push_size(&result->matches, &file_match, sizeof(file_match));
@@ -309,7 +307,7 @@ keep_going:;
if (read_cursor >= new_result->files.length)
continue;
- ts_found_file *f = (ts_found_file *)ts_array_at(&new_result->files, read_cursor);
+ ts_found_file *f = *(ts_found_file **)ts_array_at(&new_result->files, read_cursor);
ts_file_content content = ts_platform_read_file(f->path, "rb, ccs=UTF-8");
_ts_search_file(f, content, new_result);
diff --git a/src/search.h b/src/search.h
index 008d835..f92ada5 100644
--- a/src/search.h
+++ b/src/search.h
@@ -3,7 +3,7 @@
#define MAX_INPUT_LENGTH 4096
#define MAX_ERROR_MESSAGE_LENGTH (MAX_INPUT_LENGTH)
-#define FILE_RESERVE_COUNT 100000
+#define FILE_RESERVE_COUNT 1000
#define ERROR_RESERVE_COUNT 100
#include "array.h"