diff --git a/infer/src/bufferoverrun/bufferOverrunDomain.ml b/infer/src/bufferoverrun/bufferOverrunDomain.ml index 13e3fbc09..5d9df444f 100644 --- a/infer/src/bufferoverrun/bufferOverrunDomain.ml +++ b/infer/src/bufferoverrun/bufferOverrunDomain.ml @@ -450,7 +450,9 @@ module Val = struct (if may_last_field then ", may_last_field" else "") (if is_java then ", is_java" else "") ; match typ.Typ.desc with - | Tint IBool | Tfloat _ | Tfun _ | TVar _ -> + | Tint (IBool | IChar | ISChar | IUChar) -> + itv_val ~non_int:(Language.curr_language_is Java) + | Tfloat _ | Tfun _ | TVar _ -> itv_val ~non_int:true | Tint _ | Tvoid -> itv_val ~non_int:false diff --git a/infer/tests/codetoanalyze/c/performance/cost_test.c b/infer/tests/codetoanalyze/c/performance/cost_test.c index 847a014c4..7f607a2be 100644 --- a/infer/tests/codetoanalyze/c/performance/cost_test.c +++ b/infer/tests/codetoanalyze/c/performance/cost_test.c @@ -4,6 +4,8 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ +#include + // Cost: 5 int foo_OK() { int i, j; @@ -147,3 +149,12 @@ void infinite() { } void call_infinite() { infinite(); } + +// Cost should not include the symbol of c. +void ignore_character_symbols_constant_FP(char c) { + for (; c < 'z';) { + if (rand()) { + c = 'a'; + } + } +} diff --git a/infer/tests/codetoanalyze/c/performance/issues.exp b/infer/tests/codetoanalyze/c/performance/issues.exp index 5a81eeabb..c54accd1e 100644 --- a/infer/tests/codetoanalyze/c/performance/issues.exp +++ b/infer/tests/codetoanalyze/c/performance/issues.exp @@ -19,16 +19,17 @@ codetoanalyze/c/performance/compound_loop_guard.c, while_and_or, 0, INFINITE_EXE codetoanalyze/c/performance/compound_loop_guard.c, while_and_or, 2, CONDITION_ALWAYS_TRUE, no_bucket, WARNING, [Here] codetoanalyze/c/performance/compound_loop_guard.c, while_and_or, 3, INTEGER_OVERFLOW_L5, no_bucket, ERROR, [,Assignment,Binary operation: ([0, +oo] + 1):signed32] codetoanalyze/c/performance/cost_test.c, alias_OK, 5, INTEGER_OVERFLOW_L5, no_bucket, ERROR, [Binary operation: ([-oo, +oo] + 1):signed32] -codetoanalyze/c/performance/cost_test.c, call_infinite, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Call to infinite,Unbounded loop,Loop at line 144, column 3] +codetoanalyze/c/performance/cost_test.c, call_infinite, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Call to infinite,Unbounded loop,Loop at line 146, column 3] codetoanalyze/c/performance/cost_test.c, call_while_upto20_minus100_bad, 0, EXPENSIVE_EXECUTION_TIME, no_bucket, ERROR, [with estimated cost 606, O(1), degree = 0] -codetoanalyze/c/performance/cost_test.c, infinite, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Unbounded loop,Loop at line 144, column 3] +codetoanalyze/c/performance/cost_test.c, ignore_character_symbols_constant_FP, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Unbounded loop,Loop at line 155, column 3] +codetoanalyze/c/performance/cost_test.c, infinite, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Unbounded loop,Loop at line 146, column 3] codetoanalyze/c/performance/cost_test.c, infinite, 3, INTEGER_OVERFLOW_L5, no_bucket, ERROR, [,Assignment,,Assignment,Binary operation: ([-oo, +oo] + [0, +oo]):signed32] codetoanalyze/c/performance/cost_test.c, infinite_FN, 3, INTEGER_OVERFLOW_L5, no_bucket, ERROR, [,Assignment,,Assignment,Binary operation: ([-oo, +oo] + [0, +oo]):signed32] codetoanalyze/c/performance/cost_test.c, loop0_bad, 2, EXPENSIVE_EXECUTION_TIME, no_bucket, ERROR, [with estimated cost 1103, O(1), degree = 0] codetoanalyze/c/performance/cost_test.c, loop1_bad, 3, EXPENSIVE_EXECUTION_TIME, no_bucket, ERROR, [with estimated cost 1205, O(1), degree = 0] -codetoanalyze/c/performance/cost_test.c, loop2_bad, 2, EXPENSIVE_EXECUTION_TIME, no_bucket, ERROR, [with estimated cost 2 + 10 ⋅ k + 2 ⋅ (1+max(0, k)), O(k), degree = 1,{1+max(0, k)},Loop at line 85, column 3,{k},Loop at line 85, column 3] +codetoanalyze/c/performance/cost_test.c, loop2_bad, 2, EXPENSIVE_EXECUTION_TIME, no_bucket, ERROR, [with estimated cost 2 + 10 ⋅ k + 2 ⋅ (1+max(0, k)), O(k), degree = 1,{1+max(0, k)},Loop at line 87, column 3,{k},Loop at line 87, column 3] codetoanalyze/c/performance/cost_test.c, main_bad, 8, EXPENSIVE_EXECUTION_TIME, no_bucket, ERROR, [with estimated cost 206, O(1), degree = 0] -codetoanalyze/c/performance/cost_test.c, while_upto20_bad, 1, EXPENSIVE_EXECUTION_TIME, no_bucket, ERROR, [with estimated cost 1 + 4 ⋅ (-m + 20) + (21-min(20, m)), O((-m + 21)), degree = 1,{21-min(20, m)},Loop at line 117, column 3,{-m + 20},Loop at line 117, column 3] +codetoanalyze/c/performance/cost_test.c, while_upto20_bad, 1, EXPENSIVE_EXECUTION_TIME, no_bucket, ERROR, [with estimated cost 1 + 4 ⋅ (-m + 20) + (21-min(20, m)), O((-m + 21)), degree = 1,{21-min(20, m)},Loop at line 119, column 3,{-m + 20},Loop at line 119, column 3] codetoanalyze/c/performance/cost_test_deps.c, if_bad_loop, 2, EXPENSIVE_EXECUTION_TIME, no_bucket, ERROR, [with estimated cost 201, O(1), degree = 0] codetoanalyze/c/performance/cost_test_deps.c, if_bad_loop, 4, INTEGER_OVERFLOW_L5, no_bucket, ERROR, [,Assignment,Binary operation: ([0, +oo] + 1):signed32] codetoanalyze/c/performance/cost_test_deps.c, loop_despite_inferbo, 3, EXPENSIVE_EXECUTION_TIME, no_bucket, ERROR, [with estimated cost 1205, O(1), degree = 0] diff --git a/infer/tests/codetoanalyze/java/performance/Cost_test.java b/infer/tests/codetoanalyze/java/performance/Cost_test.java index d9f2b42d1..5229d270a 100644 --- a/infer/tests/codetoanalyze/java/performance/Cost_test.java +++ b/infer/tests/codetoanalyze/java/performance/Cost_test.java @@ -170,4 +170,13 @@ public class Cost_test { } } } + + // Cost should not include the symbol of c. + void ignore_character_symbols_constant(char c) { + for (; c < 'z'; ) { + if (rand()) { + c = 'a'; + } + } + } }