Skip to content

Commit

Permalink
Fix warning threshold as it was causing too many warnings after 8c11db3.
Browse files Browse the repository at this point in the history
Also fix the test cases that were supposed to catch this regression and didn't.
  • Loading branch information
plusvic committed Aug 15, 2018
1 parent 2d8da2d commit 537fd58
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion libyara/include/yara/limits.h
Expand Up @@ -77,7 +77,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// specify the threshold when calling yr_compiler_set_atom_quality_table
#ifndef YR_ATOM_QUALITY_WARNING_THRESHOLD
#define YR_ATOM_QUALITY_WARNING_THRESHOLD \
(YR_MAX_ATOM_QUALITY - 2 * YR_MAX_ATOM_LENGTH + 5)
(YR_MAX_ATOM_QUALITY - 2 * YR_MAX_ATOM_LENGTH + 4)
#endif


Expand Down
21 changes: 18 additions & 3 deletions tests/test-rules.c
Expand Up @@ -1914,6 +1914,16 @@ void test_performance_warnings()
strings: $a = { 01 ?? ?? 02 } \
condition: $a }")

assert_warning(
"rule test { \
strings: $a = { 00 01 } \
condition: $a }")

assert_warning(
"rule test { \
strings: $a = { 01 00 } \
condition: $a }")

assert_warning(
"rule test { \
strings: $a = { 00 00 } \
Expand Down Expand Up @@ -1944,17 +1954,22 @@ void test_performance_warnings()
strings: $a = { FF FF FF FF } \
condition: $a }")

assert_no_warning(
assert_no_warnings(
"rule test { \
strings: $a = { 00 01 02 03 } \
condition: $a }")

assert_no_warnings(
"rule test { \
strings: $a = { 01 02 03 04 } \
condition: $a }")

assert_no_warning(
assert_no_warnings(
"rule test { \
strings: $a = { 01 02 03 } \
condition: $a }")

assert_no_warning(
assert_no_warnings(
"rule test { \
strings: $a = { 01 02 } \
condition: $a }")
Expand Down
22 changes: 20 additions & 2 deletions tests/util.h
Expand Up @@ -177,7 +177,7 @@ int read_file(
int result = compile_rule(rule, &rules); \
if (result == ERROR_SUCCESS) { \
yr_rules_destroy(rules); \
if (warnings < w) { \
if (warnings < w) { \
fprintf(stderr, "%s:%d: expecting warning\n", \
__FILE__, __LINE__); \
exit(EXIT_FAILURE); \
Expand All @@ -191,8 +191,26 @@ int read_file(
} while (0);


#define assert_no_warnings(rule) do { \
YR_RULES* rules; \
int result = compile_rule(rule, &rules); \
if (result == ERROR_SUCCESS) { \
yr_rules_destroy(rules); \
if (warnings > 0) { \
fprintf(stderr, "%s:%d: unexpected warning\n", \
__FILE__, __LINE__); \
exit(EXIT_FAILURE); \
} \
} \
else { \
fprintf(stderr, "%s:%d: failed to compile << %s >>: %s\n", \
__FILE__, __LINE__, rule, compile_error); \
exit(EXIT_FAILURE); \
} \
} while (0);


#define assert_warning(rule) assert_warnings(rule, 1)
#define assert_no_warning(rule) assert_warnings(rule, 0)


#define assert_true_regexp(regexp,string,expected) do { \
Expand Down

0 comments on commit 537fd58

Please sign in to comment.