diff --git a/.stylua.toml b/.stylua.toml index df96b7b..ecb6dca 100644 --- a/.stylua.toml +++ b/.stylua.toml @@ -3,4 +3,4 @@ line_endings = "Unix" indent_type = "Spaces" indent_width = 2 quote_style = "AutoPreferDouble" -no_call_parentheses = true +call_parentheses = "None" diff --git a/Makefile b/Makefile index 7a2cece..db6d9a6 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,4 @@ CFLAGS = -Wall -Werror -fpic -std=gnu99 -COVERAGE ?= ifeq ($(OS),Windows_NT) MKD = -mkdir @@ -19,7 +18,7 @@ build/$(TARGET): src/fzf.c src/fzf.h $(CC) -O3 $(CFLAGS) -shared src/fzf.c -o build/$(TARGET) build/test: build/$(TARGET) test/test.c - $(CC) -Og -ggdb3 $(CFLAGS) $(COVERAGE) test/test.c -o build/test -I./src -L./build -lfzf -lexaminer + $(CC) -Og -ggdb3 $(CFLAGS) test/test.c -o build/test -I./src -L./build -lfzf -lexaminer build/benchmark: build/$(TARGET) test/benchmark.c $(CC) -O3 $(CFLAGS) test/benchmark.c -o build/benchmark -I./src -L./build -lfzf -lcurl -lm @@ -31,10 +30,6 @@ lint: format: clang-format --style=file --dry-run -Werror src/fzf.c src/fzf.h test/test.c test/benchmark.c -debug: - $(MKD) build - $(CC) -Og -ggdb3 $(CFLAGS) $(COVERAGE) -shared src/fzf.c -o build/$(TARGET) - test: build/test @LD_LIBRARY_PATH=${PWD}/build:${LD_LIBRARY_PATH} ./build/test diff --git a/src/fzf.c b/src/fzf.c index 7043748..d912482 100644 --- a/src/fzf.c +++ b/src/fzf.c @@ -199,7 +199,7 @@ static size_t min64u(size_t a, size_t b) { } static fzf_position_t *pos_array(bool with_pos, size_t len) { - if (with_pos) { + if (with_pos && len > 0) { fzf_position_t *pos = (fzf_position_t *)malloc(sizeof(fzf_position_t)); pos->size = 0; pos->cap = len; @@ -1232,7 +1232,10 @@ int32_t fzf_get_score(const char *text, fzf_pattern_t *pattern, } current_score = res.score; matched = true; - } else if (term->inv) { + break; + } + + if (term->inv) { current_score = 0; matched = true; } @@ -1274,7 +1277,10 @@ fzf_position_t *fzf_get_positions(const char *text, fzf_pattern_t *pattern, } current_res = res; matched = true; - } else if (term->inv) { + break; + } + + if (term->inv) { matched = true; } } diff --git a/test/test.c b/test/test.c index 156ab1d..f6e26f8 100644 --- a/test/test.c +++ b/test/test.c @@ -738,6 +738,13 @@ TEST(pos_integration, simple_or) { pos_wrapper("'src | ^Lua", input, expected); } +TEST(pos_integration, or_mem_leak) { + char *input[] = {"src/fzf.h", NULL}; + int match1[] = {2, 1, 0, -1}; + int *expected[] = {match1}; + pos_wrapper("src | src", input, expected); +} + TEST(pos_integration, complex_term) { char *input[] = {"lua/random_previewer", "README.md", "previewers/utils.lua", "previewers/buffer.lua",