From 809100d6124eb85f703c75171ee3b454259d31d5 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Tue, 18 Dec 2018 08:21:59 -0800 Subject: [PATCH] [inferbo] Prettier field name for Java in traces Reviewed By: ngorogiannis Differential Revision: D13505750 fbshipit-source-id: f9a322449 --- infer/src/bufferoverrun/absLoc.ml | 2 +- .../java/bufferoverrun/CompressedData.java | 40 +++++++++++++++++++ .../java/bufferoverrun/issues.exp | 1 + 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 infer/tests/codetoanalyze/java/bufferoverrun/CompressedData.java diff --git a/infer/src/bufferoverrun/absLoc.ml b/infer/src/bufferoverrun/absLoc.ml index e46a1a5bd..4247667a2 100644 --- a/infer/src/bufferoverrun/absLoc.ml +++ b/infer/src/bufferoverrun/absLoc.ml @@ -126,7 +126,7 @@ module Loc = struct | Field (Allocsite (Allocsite.Known {path= Some (SP.Deref (SP.Deref_CPointer, p))}), f) -> F.fprintf fmt "%a->%s" (SP.pp_partial_paren ~paren:true) p (Typ.Fieldname.to_flat_string f) | Field (l, f) -> - F.fprintf fmt "%a.%a" (pp_paren ~paren:true) l Typ.Fieldname.pp f + F.fprintf fmt "%a.%s" (pp_paren ~paren:true) l (Typ.Fieldname.to_flat_string f) let pp = pp_paren ~paren:false diff --git a/infer/tests/codetoanalyze/java/bufferoverrun/CompressedData.java b/infer/tests/codetoanalyze/java/bufferoverrun/CompressedData.java new file mode 100644 index 000000000..2eff119f7 --- /dev/null +++ b/infer/tests/codetoanalyze/java/bufferoverrun/CompressedData.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2018-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +package codetoanalyze.java.bufferoverrun; + +/* Mimics https://fburl.com/f61h6rbl */ +class CompressedData { + class C { + public static final int CCI = 4; + } + + class DI { + int s; + } + + class D { + final DI[] cci = new DI[C.CCI]; + int cis; + } + + int yy; + + int decompressData(D d) { + int output = 0; + DI di; + final int cis = d.cis; + + for (int y = 0; y < yy; ++y) { + for (int ci = 0; ci < cis; ++ci) { + di = d.cci[ci]; + final int s = di.s; + output = y * s; + } + } + return output; + } +} diff --git a/infer/tests/codetoanalyze/java/bufferoverrun/issues.exp b/infer/tests/codetoanalyze/java/bufferoverrun/issues.exp index 57ec24456..d9c62fe1c 100644 --- a/infer/tests/codetoanalyze/java/bufferoverrun/issues.exp +++ b/infer/tests/codetoanalyze/java/bufferoverrun/issues.exp @@ -1 +1,2 @@ codetoanalyze/java/bufferoverrun/Array.java, codetoanalyze.java.bufferoverrun.Array.collection_add_zero_Bad():java.util.ArrayList, 2, BUFFER_OVERRUN_L1, no_bucket, ERROR, [,Array declaration,Assignment,Array access: Offset: 0 Size: 0] +codetoanalyze/java/bufferoverrun/CompressedData.java, codetoanalyze.java.bufferoverrun.CompressedData.decompressData(codetoanalyze.java.bufferoverrun.CompressedData$D):int, 9, INTEGER_OVERFLOW_L5, no_bucket, ERROR, [,Assignment,,Assignment,Binary operation: ([0, this.yy.ub - 1] × [-oo, +oo]):signed32]