diff --git a/infer/src/IR/AttributesTable.re b/infer/src/IR/AttributesTable.re index 83fc6bf83..494ab8612 100644 --- a/infer/src/IR/AttributesTable.re +++ b/infer/src/IR/AttributesTable.re @@ -53,7 +53,8 @@ let store_attributes (proc_attributes: ProcAttributes.t) => { | None => true | Some proc_attributes_on_disk => let higher_rank_than_on_disk () => - DB.source_file_compare proc_attributes.loc.file proc_attributes_on_disk.loc.file > 0; + proc_attributes.is_defined && + DB.source_file_compare proc_attributes.loc.file proc_attributes_on_disk.loc.file > 0; let becomes_defined = proc_attributes.is_defined && not proc_attributes_on_disk.is_defined; /* Only overwrite the attribute file if the procedure becomes defined or its associated file has higher rank (alphabetically) than on disk. */ diff --git a/infer/tests/codetoanalyze/cpp/errors/Makefile b/infer/tests/codetoanalyze/cpp/errors/Makefile index 001fe7048..35f01956d 100644 --- a/infer/tests/codetoanalyze/cpp/errors/Makefile +++ b/infer/tests/codetoanalyze/cpp/errors/Makefile @@ -25,6 +25,7 @@ FILES = \ nestedoperators/*.cpp \ npe/*.cpp \ numeric/*.cpp \ + overwrite_attribute/*.cpp \ reference/*.cpp \ resource_leaks/*.cpp \ smart_ptr/*.cpp \ diff --git a/infer/tests/codetoanalyze/cpp/errors/issues.exp b/infer/tests/codetoanalyze/cpp/errors/issues.exp index d0354be09..6ee7e6030 100644 --- a/infer/tests/codetoanalyze/cpp/errors/issues.exp +++ b/infer/tests/codetoanalyze/cpp/errors/issues.exp @@ -116,6 +116,7 @@ numeric/min_max.cpp, max_X_inv_div0, 2, DIVIDE_BY_ZERO numeric/min_max.cpp, max_int_div0, 0, DIVIDE_BY_ZERO numeric/min_max.cpp, min_X_div0, 2, DIVIDE_BY_ZERO numeric/min_max.cpp, min_int_div0, 0, DIVIDE_BY_ZERO +overwrite_attribute/main.cpp, testSetIntValue, 3, DIVIDE_BY_ZERO reference/reference_field.cpp, reference_field::ptr_F_div0, 5, DIVIDE_BY_ZERO reference/reference_field.cpp, reference_field::ptr_I_div0, 5, DIVIDE_BY_ZERO reference/reference_field.cpp, reference_field::ptr_getF_div0, 5, DIVIDE_BY_ZERO diff --git a/infer/tests/codetoanalyze/cpp/errors/overwrite_attribute/lib.cpp b/infer/tests/codetoanalyze/cpp/errors/overwrite_attribute/lib.cpp new file mode 100644 index 000000000..6f89a6122 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/errors/overwrite_attribute/lib.cpp @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2016 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#include "lib.h" + +void setIntValue(int* x, int val) { *x = val; } diff --git a/infer/tests/codetoanalyze/cpp/errors/overwrite_attribute/lib.h b/infer/tests/codetoanalyze/cpp/errors/overwrite_attribute/lib.h new file mode 100644 index 000000000..faf4908ae --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/errors/overwrite_attribute/lib.h @@ -0,0 +1,10 @@ +/* + * Copyright (c) 2016 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +void setIntValue(int* x, int val); diff --git a/infer/tests/codetoanalyze/cpp/errors/overwrite_attribute/main.cpp b/infer/tests/codetoanalyze/cpp/errors/overwrite_attribute/main.cpp new file mode 100644 index 000000000..0ba90f550 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/errors/overwrite_attribute/main.cpp @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2016 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#include "lib.h" + +int testSetIntValue() { + int x; + setIntValue(&x, 0); + return 1 / x; // div0 +}