summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-03-04 20:49:02 +0100
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-03-04 20:49:02 +0100
commit305b9dd7c40abf1e8936937e539f7565423183da (patch)
treebf20e903e44ba26fee58fd804b71ea7b4b769f1e
parentd515025b35b1d0fdbc0e1df74a0dffd06a9cc954 (diff)
size check everywhere
-rw-r--r--src/main_windows.cpp14
-rw-r--r--src/search.cpp7
2 files changed, 13 insertions, 8 deletions
diff --git a/src/main_windows.cpp b/src/main_windows.cpp
index 5f6e1e9..45963d1 100644
--- a/src/main_windows.cpp
+++ b/src/main_windows.cpp
@@ -266,7 +266,7 @@ void ts_platform_list_files_block(ts_search_result* result, wchar_t* start_dir)
MultiByteToWideChar(CP_UTF8, 0, result->directory_to_search, -1, search_dir, MAX_INPUT_LENGTH);
}
else {
- wcscpy(search_dir, start_dir);
+ wcscpy_s(search_dir, MAX_INPUT_LENGTH, start_dir);
}
// Append wildcard
@@ -300,9 +300,9 @@ void ts_platform_list_files_block(ts_search_result* result, wchar_t* start_dir)
continue;
wchar_t* subdir_buffer_path = (wchar_t*)ts_memory_bucket_reserve(&result->memory, MAX_INPUT_LENGTH);
- wcscpy(subdir_buffer_path, search_dir);
- wcscat(subdir_buffer_path, L"\\");
- wcscat(subdir_buffer_path, name);
+ wcscpy_s(subdir_buffer_path, MAX_INPUT_LENGTH, search_dir);
+ wcscat_s(subdir_buffer_path, MAX_INPUT_LENGTH, L"\\");
+ wcscat_s(subdir_buffer_path, MAX_INPUT_LENGTH, name);
ts_platform_list_files_block(result, subdir_buffer_path);
}
else if ((file_info.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED) ||
@@ -321,9 +321,9 @@ void ts_platform_list_files_block(ts_search_result* result, wchar_t* start_dir)
(void)matched_filter;
wchar_t complete_file_path[MAX_INPUT_LENGTH];
- wcscpy(complete_file_path, search_dir);
- wcscat(complete_file_path, L"\\");
- wcscat(complete_file_path, name);
+ wcscpy_s(complete_file_path, MAX_INPUT_LENGTH, search_dir);
+ wcscat_s(complete_file_path, MAX_INPUT_LENGTH, L"\\");
+ wcscat_s(complete_file_path, MAX_INPUT_LENGTH, name);
ts_found_file* f = (ts_found_file*)ts_memory_bucket_reserve(&result->memory, sizeof(ts_found_file));
f->path = (utf8_int8_t*)ts_memory_bucket_reserve(&result->memory, MAX_INPUT_LENGTH);
diff --git a/src/search.cpp b/src/search.cpp
index dc0534a..38bda76 100644
--- a/src/search.cpp
+++ b/src/search.cpp
@@ -271,7 +271,8 @@ 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);
+ if (total_len > MAX_INPUT_LENGTH) total_len = MAX_INPUT_LENGTH;
+ utf8ncpy(file_match.line_info, m->line_start, total_len);
utf8_int32_t ch;
utf8_int8_t* iter = file_match.line_info;
@@ -367,6 +368,10 @@ static void _ts_list_files(ts_search_result* result)
void ts_start_search(utf8_int8_t *path, utf8_int8_t *filter, utf8_int8_t *query)
{
+ if (utf8len(query) > 0 && utf8len(query) <= 2) { // need a string of atleast 3 characters
+ return;
+ }
+
if (current_search_result)
{
current_search_result->cancel_search = true;