================ @@ -0,0 +1,326 @@ +//===- NullTerminatedChecker.cpp - Check null_terminated params -*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This defines NullTerminatedChecker, which checks for arguments treated as +// buffers that are expected to be null-terminated (ends with a zero-valued +// element). A constant-size array is considered null-terminated if any of its +// elements may be zero on the current path. +// +// Parameters are marked as expecting null-terminated buffers using: +// __attribute__((annotate("null_terminated"))) +// +//===----------------------------------------------------------------------===// + +#include "clang/AST/Attr.h" +#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" +#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" +#include "clang/StaticAnalyzer/Core/Checker.h" +#include "clang/StaticAnalyzer/Core/CheckerManager.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" +#include "llvm/ADT/SmallBitVector.h" + +using namespace clang; +using namespace ento; + +namespace { +class NullTerminatedChecker : public Checker<check::PreCall> { +public: + // TODO: region-store-max-binding-fanout defaults to 128, meaning a single + // bind only covers that many elements. The 1024 option here is only truly + // respected when the array is built by separate bind operations, e.g., + // the case of straight-line writes: + // + // int a[500]; + // a[0] = val; + // a[1] = val; + // ... + // a[499] = val; + int MaxArraySize = 1024; ---------------- NagyDonat wrote:
Why don't you set the default value of `MaxArraySize` to 128 to match the default value of `region-store-max-binding-fanout`? I think building the array with separate bindings is vanishingly rare, saying that `MaxArraySize` defaults to 1024 will just mislead the users, who will be confused when they see that the setting is not respected. https://github.com/llvm/llvm-project/pull/188128 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
