diff options
| author | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-03-14 18:55:57 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-03-14 18:55:57 +0100 |
| commit | f2b44f582dbb9d898e6aad1db6919b5a295815be (patch) | |
| tree | 4c4b495c5c063a308c19e932c14aca45e7500954 | |
| parent | 33caee123ae6e79f251d1cd9d45ca62332e8d55b (diff) | |
static analysis fixes
| -rw-r--r-- | build_win32.bat | 2 | ||||
| -rw-r--r-- | src/array.cpp | 34 | ||||
| -rw-r--r-- | src/array.h | 3 | ||||
| -rw-r--r-- | src/config.cpp | 18 | ||||
| -rw-r--r-- | src/config.h | 4 | ||||
| -rw-r--r-- | src/export.cpp | 23 | ||||
| -rw-r--r-- | src/import.cpp | 10 | ||||
| -rw-r--r-- | src/main.cpp | 6 | ||||
| -rw-r--r-- | src/memory_bucket.cpp | 2 | ||||
| -rw-r--r-- | src/search.cpp | 21 | ||||
| -rw-r--r-- | src/windows/main_windows.cpp | 12 |
11 files changed, 73 insertions, 62 deletions
diff --git a/build_win32.bat b/build_win32.bat index a2b8de6..cd1323f 100644 --- a/build_win32.bat +++ b/build_win32.bat @@ -13,6 +13,6 @@ if "%1"=="-release" ( ) mkdir %OUT_DIR% -cl /std:c++17 /nologo %FLAGS% /W3 /Zi /MD /EHsc /Isrc/windows /Iimgui /Iimgui/backends /Isrc /utf-8 %INCLUDES% /D UNICODE /D _UNICODE %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fd%OUT_DIR%/vc140.pdb /Fo%OUT_DIR%/ /link %LIBS% +cl /analyze /std:c++17 /nologo %FLAGS% /W3 /Zi /MD /EHsc /Isrc/windows /Iimgui /Iimgui/backends /Isrc /utf-8 %INCLUDES% /D UNICODE /D _UNICODE %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fd%OUT_DIR%/vc140.pdb /Fo%OUT_DIR%/ /link %LIBS% if "%1"=="-r" call "bin/debug/text-search.exe" if "%1"=="-d" call devenv "bin/debug/text-search.exe" diff --git a/src/array.cpp b/src/array.cpp index 6cdc8f4..fe91732 100644 --- a/src/array.cpp +++ b/src/array.cpp @@ -1,5 +1,5 @@ #include "array.h" - +#include "config.h" #include <stdlib.h> #include <cstring> @@ -18,9 +18,9 @@ ts_array ts_array_create(uint32_t entry_size) uint32_t ts_array_push(ts_array *ts_array, void *data) { - ASSERT(ts_array); - ASSERT(data); - ASSERT(ts_array->reserve_jump >= 1); + assert(ts_array); + assert(data); + assert(ts_array->reserve_jump >= 1); ts_mutex_lock(&ts_array->mutex); ts_array->length++; @@ -47,9 +47,9 @@ uint32_t ts_array_push(ts_array *ts_array, void *data) uint32_t ts_array_push_size(ts_array *ts_array, void *data, uint32_t data_size) { - ASSERT(ts_array); - ASSERT(data); - ASSERT(ts_array->reserve_jump >= 1); + assert(ts_array); + assert(data); + assert(ts_array->reserve_jump >= 1); ts_mutex_lock(&ts_array->mutex); ts_array->length++; @@ -84,7 +84,7 @@ uint32_t ts_array_push_size(ts_array *ts_array, void *data, uint32_t data_size) void ts_array_reserve(ts_array *ts_array, uint32_t reserve_count) { - ASSERT(ts_array); + assert(ts_array); ts_mutex_lock(&ts_array->mutex); uint32_t reserved_count = ts_array->reserved_length - ts_array->length; @@ -108,9 +108,9 @@ void ts_array_reserve(ts_array *ts_array, uint32_t reserve_count) void ts_array_remove_at(ts_array *ts_array, uint32_t at) { - ASSERT(ts_array); - ASSERT(at >= 0); - ASSERT(at < ts_array->length); + assert(ts_array); + assert(at >= 0); + assert(at < ts_array->length); ts_mutex_lock(&ts_array->mutex); if (ts_array->length > 1) @@ -139,7 +139,7 @@ void ts_array_remove(ts_array *ts_array, void *ptr) void ts_array_remove_by(ts_array *ts_array, void *data) { - ASSERT(ts_array); + assert(ts_array); ts_mutex_lock(&ts_array->mutex); for (uint32_t i = 0; i < ts_array->length; i++) @@ -157,9 +157,9 @@ void ts_array_remove_by(ts_array *ts_array, void *data) void *ts_array_at(ts_array *ts_array, uint32_t at) { ts_mutex_lock(&ts_array->mutex); - ASSERT(ts_array); - ASSERT(at >= 0); - ASSERT(at < ts_array->length); + assert(ts_array); + assert(at >= 0); + assert(at < ts_array->length); void *result = (char*)ts_array->data + (at * ts_array->entry_size); ts_mutex_unlock(&ts_array->mutex); @@ -168,7 +168,7 @@ void *ts_array_at(ts_array *ts_array, uint32_t at) void ts_array_destroy(ts_array *ts_array) { - ASSERT(ts_array); + assert(ts_array); free(ts_array->data); ts_mutex_destroy(&ts_array->mutex); } @@ -180,6 +180,8 @@ ts_array ts_array_copy(ts_array *arr) new_ts_array.reserved_length = arr->reserved_length; new_ts_array.entry_size = arr->entry_size; new_ts_array.data = malloc(new_ts_array.entry_size*new_ts_array.reserved_length); + if (!new_bucket.data) exit_oom(); + new_ts_array.mutex = ts_mutex_create(); ts_mutex_lock(&arr->mutex); diff --git a/src/array.h b/src/array.h index 6697548..9e82e62 100644 --- a/src/array.h +++ b/src/array.h @@ -1,9 +1,8 @@ #ifndef INCLUDE_ts_array #define INCLUDE_ts_array -#define ASSERT(e_) {if(!(e_)){*(int*)0=0;}} - #include "mutex.h" +#include <cassert> #include <cstdint> typedef struct t_ts_array diff --git a/src/config.cpp b/src/config.cpp index ef3f4be..d7f1a43 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -23,19 +23,19 @@ static void _ts_config_ReadLine(ImGuiContext*, ImGuiSettingsHandler*, void* entr uint32_t threads = 1, maxSize = 100, matchCase = 0; #if defined(_WIN32) - if (sscanf_s(line, "Path=%s", (char*)&path, MAX_INPUT_LENGTH) == 1) { strncpy_s(path_buffer, MAX_INPUT_LENGTH, (char*)path, MAX_INPUT_LENGTH); } - else if (sscanf_s(line, "Filter=%s", (char*)&filter, MAX_INPUT_LENGTH) == 1) { strncpy_s(filter_buffer, MAX_INPUT_LENGTH, (char*)filter, MAX_INPUT_LENGTH); } - else if (sscanf_s(line, "Query=%s", (char*)&query, MAX_INPUT_LENGTH) == 1) { strncpy_s(query_buffer, MAX_INPUT_LENGTH, (char*)query, MAX_INPUT_LENGTH); } - else if (sscanf_s(line, "Threads=%d", &threads) == 1) { ts_thread_count = threads; } - else if (sscanf_s(line, "MaxSize=%d", &maxSize) == 1) { max_file_size = maxSize; } - else if (sscanf_s(line, "MatchCase=%d", &matchCase) == 1) { respect_capitalization = matchCase; } + if (sscanf_s(line, "Path=%s", (char*)&path, MAX_INPUT_LENGTH-1) == 1) { strncpy_s(path_buffer, MAX_INPUT_LENGTH, (char*)path, MAX_INPUT_LENGTH-1); } + else if (sscanf_s(line, "Filter=%s", (char*)&filter, MAX_INPUT_LENGTH-1) == 1) { strncpy_s(filter_buffer, MAX_INPUT_LENGTH, (char*)filter, MAX_INPUT_LENGTH-1); } + else if (sscanf_s(line, "Query=%s", (char*)&query, MAX_INPUT_LENGTH-1) == 1) { strncpy_s(query_buffer, MAX_INPUT_LENGTH, (char*)query, MAX_INPUT_LENGTH-1); } + else if (sscanf_s(line, "Threads=%u", &threads) == 1) { ts_thread_count = threads; } + else if (sscanf_s(line, "MaxSize=%u", &maxSize) == 1) { max_file_size = maxSize; } + else if (sscanf_s(line, "MatchCase=%u", &matchCase) == 1) { respect_capitalization = matchCase; } #elif defined(__linux__) || defined(__APPLE__) if (sscanf(line, "Path=%s", (char*)&path) == 1) { strncpy(path_buffer, (char*)path, MAX_INPUT_LENGTH); } else if (sscanf(line, "Filter=%s", (char*)&filter) == 1) { strncpy(filter_buffer, (char*)filter, MAX_INPUT_LENGTH); } else if (sscanf(line, "Query=%s", (char*)&query) == 1) { strncpy(query_buffer, (char*)query, MAX_INPUT_LENGTH); } - else if (sscanf(line, "Threads=%d", &threads) == 1) { ts_thread_count = threads; } - else if (sscanf(line, "MaxSize=%d", &maxSize) == 1) { max_file_size = maxSize; } - else if (sscanf(line, "MatchCase=%d", &matchCase) == 1) { respect_capitalization = matchCase; } + else if (sscanf(line, "Threads=%u", &threads) == 1) { ts_thread_count = threads; } + else if (sscanf(line, "MaxSize=%u", &maxSize) == 1) { max_file_size = maxSize; } + else if (sscanf(line, "MatchCase=%u", &matchCase) == 1) { respect_capitalization = matchCase; } #endif } diff --git a/src/config.h b/src/config.h index 408cf63..20e63e9 100644 --- a/src/config.h +++ b/src/config.h @@ -1,13 +1,15 @@ #pragma once #if defined(_WIN32) -#define MAX_INPUT_LENGTH 32767 +#define MAX_INPUT_LENGTH 4096 #elif defined(__linux__) #define MAX_INPUT_LENGTH 4096 #elif defined(__APPLE__) #define MAX_INPUT_LENGTH 1024 #endif +#define exit_oom() { perror("Out of memory."); exit(-1); } + #define AUTHOR "created by Aldrik Ramaekers" #define CONTACT "<aldrik.ramaekers@gmail.com>" diff --git a/src/export.cpp b/src/export.cpp index 6adab07..493c978 100644 --- a/src/export.cpp +++ b/src/export.cpp @@ -64,9 +64,9 @@ static bool _ts_export_json(ts_search_result* result, const utf8_int8_t* path) { fprintf(write_file, "\"path\": \"%s\",\n", _json_escape_str(result->directory_to_search, escape_buffer, escape_size)); fprintf(write_file, "\"filter\": \"%s\",\n", _json_escape_str(result->file_filter, escape_buffer, escape_size)); fprintf(write_file, "\"query\": \"%s\",\n", _json_escape_str(result->search_text, escape_buffer, escape_size)); - fprintf(write_file, "\"casesensitive\": %d,\n", result->respect_capitalization); - fprintf(write_file, "\"match_count\": %d,\n", result->match_count); - fprintf(write_file, "\"file_count\": %d,\n", result->file_count); + fprintf(write_file, "\"casesensitive\": %u,\n", result->respect_capitalization); + fprintf(write_file, "\"match_count\": %u,\n", result->match_count); + fprintf(write_file, "\"file_count\": %u,\n", result->file_count); fprintf(write_file, "\"timestamp\": %llu,\n", result->timestamp); fprintf(write_file, "\"files\": [\n"); @@ -105,7 +105,7 @@ static bool _ts_export_json(ts_search_result* result, const utf8_int8_t* path) { if (!first_match_of_file) fprintf(write_file, ",\n"); first_match_of_file = false; fprintf(write_file, "{\n"); - fprintf(write_file, "\"line_nr\": %d,\n", match->line_nr); + fprintf(write_file, "\"line_nr\": %u,\n", match->line_nr); fprintf(write_file, "\"match_length\": %zu,\n", match->word_match_length); fprintf(write_file, "\"match_offset\": %zu,\n", match->word_match_offset); fprintf(write_file, "\"line\": \"%s\"\n", _json_escape_str(match->line_info, escape_buffer, escape_size)); @@ -130,9 +130,9 @@ static bool _ts_export_csv(ts_search_result* result, const utf8_int8_t* path) { fprintf(write_file, "PATH,%s\n", result->directory_to_search); fprintf(write_file, "FILTER,%s\n", result->file_filter); fprintf(write_file, "QUERY,%s\n", result->search_text); - fprintf(write_file, "CASESENSITIVE,%d\n", result->respect_capitalization); - fprintf(write_file, "MATCH_COUNT,%d\n", result->match_count); - fprintf(write_file, "FILE_COUNT,%d\n", result->file_count); + fprintf(write_file, "CASESENSITIVE,%u\n", result->respect_capitalization); + fprintf(write_file, "MATCH_COUNT,%u\n", result->match_count); + fprintf(write_file, "FILE_COUNT,%u\n", result->file_count); fprintf(write_file, "TIMESTAMP,%llu\n", result->timestamp); // Empty files. @@ -193,9 +193,9 @@ static bool _ts_export_xml(ts_search_result* result, const utf8_int8_t* path) { fprintf(write_file, "<PATH>%s</PATH>\n", _xml_escape_str(result->directory_to_search, escape_buffer, escape_size)); fprintf(write_file, "<FILTER>%s</FILTER>\n", _xml_escape_str(result->file_filter, escape_buffer, escape_size)); fprintf(write_file, "<QUERY>%s</QUERY>\n", _xml_escape_str(result->search_text, escape_buffer, escape_size)); - fprintf(write_file, "<CASESENSITIVE>%d</CASESENSITIVE>\n", result->respect_capitalization); - fprintf(write_file, "<MATCH_COUNT>%d</MATCH_COUNT>\n", result->match_count); - fprintf(write_file, "<FILE_COUNT>%d</FILE_COUNT>\n", result->file_count); + fprintf(write_file, "<CASESENSITIVE>%u</CASESENSITIVE>\n", result->respect_capitalization); + fprintf(write_file, "<MATCH_COUNT>%u</MATCH_COUNT>\n", result->match_count); + fprintf(write_file, "<FILE_COUNT>%u</FILE_COUNT>\n", result->file_count); fprintf(write_file, "<TIMESTAMP>%llu</TIMESTAMP>\n", result->timestamp); // Empty files. @@ -223,7 +223,7 @@ static bool _ts_export_xml(ts_search_result* result, const utf8_int8_t* path) { } fprintf(write_file, "<MATCH>\n"); - fprintf(write_file, "<LINENR>%d</LINENR>\n", match->line_nr); + fprintf(write_file, "<LINENR>%u</LINENR>\n", match->line_nr); fprintf(write_file, "<MATCH_LENGTH>%zu</MATCH_LENGTH>\n", match->word_match_length); fprintf(write_file, "<MATCH_OFFSET>%zu</MATCH_OFFSET>\n", match->word_match_offset); fprintf(write_file, "<LINE>%s</LINE>\n", _xml_escape_str(match->line_info, escape_buffer, escape_size)); @@ -268,6 +268,7 @@ export_result ts_export_result(ts_search_result* result, const utf8_int8_t* path result->is_saving = true; struct t_export_thread_args* args = (struct t_export_thread_args*)malloc(sizeof(struct t_export_thread_args)); + if (!args) exit_oom(); args->result = result; args->path = path; diff --git a/src/import.cpp b/src/import.cpp index 571f8ae..ffa187d 100644 --- a/src/import.cpp +++ b/src/import.cpp @@ -26,8 +26,8 @@ static bool _ts_import_csv_v1(ts_search_result* result, FILE *read_file) { fscanf_required(read_file, "FILTER,%s\n", 1, (char*)result->file_filter); fscanf_required(read_file, "QUERY,%s\n", 1, (char*)result->search_text); fscanf_required(read_file, "CASESENSITIVE,%d\n", 1, (int*)&result->respect_capitalization); - fscanf_required(read_file, "MATCH_COUNT,%d\n", 1, &result->match_count); - fscanf_required(read_file, "FILE_COUNT,%d\n", 1, &result->file_count); + fscanf_required(read_file, "MATCH_COUNT,%u\n", 1, &result->match_count); + fscanf_required(read_file, "FILE_COUNT,%u\n", 1, &result->file_count); fscanf_required(read_file, "TIMESTAMP,%llu\n", 1, &result->timestamp); utf8ncpy(path_buffer, result->directory_to_search, MAX_INPUT_LENGTH); @@ -65,7 +65,7 @@ static bool _ts_import_csv_v1(ts_search_result* result, FILE *read_file) { } // New match within current_file - if (current_file && sscanf(line_buffer, "MATCH,%d,%zu,%zu\n", &match.line_nr, &match.word_match_length, &match.word_match_offset) == 3) { + if (current_file && sscanf(line_buffer, "MATCH,%u,%zu,%zu\n", &match.line_nr, &match.word_match_length, &match.word_match_offset) == 3) { match.file = current_file; utf8_int8_t* iter = line_buffer; @@ -95,11 +95,13 @@ static bool _ts_import_csv(ts_search_result* result, const utf8_int8_t* path) { int version = -1; bool res = false; - fscanf(read_file, "VERSION,%d\n", &version); + if (fscanf(read_file, "VERSION,%d\n", &version) != 1) goto done; switch(version) { case 1: res = _ts_import_csv_v1(result, read_file); break; default: break; } + + done: fclose(read_file); return res; } diff --git a/src/main.cpp b/src/main.cpp index 585d7ff..16d918e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -268,7 +268,7 @@ void _ts_create_file_match_rows() { ts_found_file *file = *(ts_found_file **)ts_array_at(¤t_search_result->files, item); char match_info_txt[20]; - snprintf(match_info_txt, 20, "#%d", item+1); + snprintf(match_info_txt, 20, "#%u", item+1); ImGui::TableNextRow(); ImGui::TableNextColumn(); @@ -349,7 +349,7 @@ void _ts_create_text_match_rows() { ImGui::TableHeader(file->file->path); ImGui::TableNextColumn(); - snprintf(match_info_txt, 20, "%d match(es)", file->file->match_count); + snprintf(match_info_txt, 20, "%u match(es)", file->file->match_count); ImGui::TableHeader(match_info_txt); ImGui::SameLine(); @@ -362,7 +362,7 @@ void _ts_create_text_match_rows() { if (file->file->collapsed) continue; char match_nr[20]; - snprintf(match_nr, 20, "#%d", item+1); + snprintf(match_nr, 20, "#%u", item+1); ImGui::TableNextRow(); ImGui::TableNextColumn(); diff --git a/src/memory_bucket.cpp b/src/memory_bucket.cpp index b199e59..952d342 100644 --- a/src/memory_bucket.cpp +++ b/src/memory_bucket.cpp @@ -1,4 +1,5 @@ #include "memory_bucket.h" +#include "config.h" #include <stdlib.h> ts_memory_bucket ts_memory_bucket_init(uint32_t bucket_size) @@ -35,6 +36,7 @@ void* ts_memory_bucket_reserve(ts_memory_bucket *bucket, uint32_t reserve_length // failed to find suitable space, allocate new bucket ts_memory_bucket_entry new_bucket; new_bucket.data = (char*)malloc(bucket_entry->length); + if (!new_bucket.data) exit_oom(); new_bucket.length = bucket_entry->length; new_bucket.cursor = reserve_length; ts_array_push(&bucket->buckets, &new_bucket); diff --git a/src/search.cpp b/src/search.cpp index d3e34ac..9c08487 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -78,6 +78,7 @@ size_t ts_filter_matches(ts_array *filters, char *string, char **matched_filter) ts_search_result *ts_create_empty_search_result() { ts_search_result *new_result_buffer = (ts_search_result *)malloc(sizeof(ts_search_result)); + if (!new_result_buffer) exit_oom(); new_result_buffer->completed_match_threads = 0; new_result_buffer->mutex = ts_mutex_create(); new_result_buffer->done_finding_files = false; @@ -123,7 +124,7 @@ bool string_is_asteriks(char *text) return true; } -bool ts_string_contains(char *text_to_search, utf8_int8_t *text_to_find, ts_array *text_matches, bool respect_capitalization) +bool ts_string_contains(char *text_to_search, utf8_int8_t *text_to_find, ts_array *text_matches, bool case_sensitive) { bool final_result = false; bool is_asteriks_only = false; @@ -156,7 +157,7 @@ bool ts_string_contains(char *text_to_search, utf8_int8_t *text_to_find, ts_arra int index = 0; while ((text_to_search = utf8codepoint(text_to_search, &text_to_search_ch)) && text_to_search_ch) { - if (!respect_capitalization) text_to_search_ch = utf8lwrcodepoint(text_to_search_ch); + if (!case_sensitive) text_to_search_ch = utf8lwrcodepoint(text_to_search_ch); word_offset_val += utf8codepointsize(text_to_search_ch); if (text_to_search_ch == '\n') { @@ -171,7 +172,7 @@ bool ts_string_contains(char *text_to_search, utf8_int8_t *text_to_find, ts_arra bool in_wildcard = false; text_to_find = utf8codepoint(text_to_find, &text_to_find_ch); - if (!respect_capitalization) text_to_find_ch = utf8lwrcodepoint(text_to_find_ch); + if (!case_sensitive) text_to_find_ch = utf8lwrcodepoint(text_to_find_ch); // text_to_search_current_attempt = utf8codepoint(text_to_search_current_attempt, //&text_to_search_current_attempt_ch); @@ -190,7 +191,7 @@ bool ts_string_contains(char *text_to_search, utf8_int8_t *text_to_find, ts_arra if (text_to_find_ch == '*') { text_to_find = utf8codepoint(text_to_find, &text_to_find_ch); - if (!respect_capitalization) text_to_find_ch = utf8lwrcodepoint(text_to_find_ch); + if (!case_sensitive) text_to_find_ch = utf8lwrcodepoint(text_to_find_ch); in_wildcard = true; } @@ -201,14 +202,14 @@ bool ts_string_contains(char *text_to_search, utf8_int8_t *text_to_find, ts_arra continue_search: if (!in_wildcard) { text_to_find = utf8codepoint(text_to_find, &text_to_find_ch); - if (!respect_capitalization) text_to_find_ch = utf8lwrcodepoint(text_to_find_ch); + if (!case_sensitive) text_to_find_ch = utf8lwrcodepoint(text_to_find_ch); } word_match_len_val += utf8codepointsize(text_to_search_current_attempt_ch); text_to_search_current_attempt = utf8codepoint( text_to_search_current_attempt, &text_to_search_current_attempt_ch); - if (!respect_capitalization) text_to_search_current_attempt_ch = utf8lwrcodepoint(text_to_search_current_attempt_ch); + if (!case_sensitive) text_to_search_current_attempt_ch = utf8lwrcodepoint(text_to_search_current_attempt_ch); if (!text_to_search_current_attempt_ch && !text_to_find_ch) goto done; @@ -275,7 +276,7 @@ static void _ts_search_file(ts_found_file *ref, ts_file_content content, ts_sear size_t bytes_to_trim = (file_match.word_match_offset - text_pad_lr); size_t bytes_trimmed = 0; utf8_int8_t* line_start_before_trim = m->line_start; - for (size_t i = 0; i < bytes_to_trim; i++) { + for (size_t x = 0; x < bytes_to_trim; x++) { utf8_int32_t ch; m->line_start = utf8codepoint(m->line_start, &ch); bytes_trimmed = (m->line_start - line_start_before_trim); @@ -398,7 +399,7 @@ static void _ts_list_files(ts_search_result* result) ts_thread_detach(&thr); } -void ts_start_search(utf8_int8_t *path, utf8_int8_t *filter, utf8_int8_t *query, uint16_t thread_count, uint32_t max_file_size, bool respect_capitalization) +void ts_start_search(utf8_int8_t *path, utf8_int8_t *filter, utf8_int8_t *query, uint16_t thread_count, uint32_t max_fs, bool case_sensitive) { if (utf8len(query) > 0 && utf8len(query) <= 2) { // need a string of atleast 3 characters return; @@ -415,8 +416,8 @@ void ts_start_search(utf8_int8_t *path, utf8_int8_t *filter, utf8_int8_t *query, snprintf(new_result->file_filter, MAX_INPUT_LENGTH, "%s", filter); new_result->filters = ts_get_filters(filter); new_result->max_ts_thread_count = thread_count; - new_result->max_file_size = max_file_size; - new_result->respect_capitalization = respect_capitalization; + new_result->max_file_size = max_fs; + new_result->respect_capitalization = case_sensitive; if (utf8len(query) == 0) { new_result->search_text = nullptr; diff --git a/src/windows/main_windows.cpp b/src/windows/main_windows.cpp index 948226f..45082ca 100644 --- a/src/windows/main_windows.cpp +++ b/src/windows/main_windows.cpp @@ -111,8 +111,9 @@ void ts_platform_set_window_title(utf8_int8_t* str) { int main(int, char**) { - OleInitialize(NULL); - CoInitializeEx(0, COINIT_MULTITHREADED|COINIT_DISABLE_OLE1DDE); + if (OleInitialize(NULL) != S_OK) { + return -1; + } ts_init(); @@ -322,7 +323,8 @@ ts_file_content ts_platform_read_file(char *path, const char *mode) } fseek(file, 0 , SEEK_END); - int length = ftell(file); + long length = ftell(file); + if (length == -1L) goto done_failure; fseek(file, 0, SEEK_SET); int length_to_alloc = length+1; @@ -330,8 +332,8 @@ ts_file_content ts_platform_read_file(char *path, const char *mode) result.content = malloc(length_to_alloc); if (!result.content) goto done; - memset(result.content, 0, length); - size_t read_result = fread(result.content, 1, length, file); + memset(result.content, 0, length_to_alloc); + size_t read_result = fread(result.content, 1, (size_t)length, file); if (read_result == 0 && length != 0) { free(result.content); |
