[clang][extract-api] Emit "navigator" property of "name" in SymbolGraph
[llvm-project.git] / compiler-rt / lib / asan / asan_scariness_score.h
blob3932973c225e2be9ecfc2c7eae285e0f93e68a11
1 //===-- asan_scariness_score.h ----------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is a part of AddressSanitizer, an address sanity checker.
11 // Compute the level of scariness of the error message.
12 // Don't expect any deep science here, just a set of heuristics that suggest
13 // that e.g. 1-byte-read-global-buffer-overflow is less scary than
14 // 8-byte-write-stack-use-after-return.
16 // Every error report has one or more features, such as memory access size,
17 // type (read or write), type of accessed memory (e.g. free-d heap, or a global
18 // redzone), etc. Every such feature has an int score and a string description.
19 // The overall score is the sum of all feature scores and the description
20 // is a concatenation of feature descriptions.
21 // Examples:
22 // 17 (4-byte-read-heap-buffer-overflow)
23 // 65 (multi-byte-write-stack-use-after-return)
24 // 10 (null-deref)
26 //===----------------------------------------------------------------------===//
28 #ifndef ASAN_SCARINESS_SCORE_H
29 #define ASAN_SCARINESS_SCORE_H
31 #include "asan_flags.h"
32 #include "sanitizer_common/sanitizer_common.h"
33 #include "sanitizer_common/sanitizer_libc.h"
35 namespace __asan {
36 struct ScarinessScoreBase {
37 void Clear() {
38 descr[0] = 0;
39 score = 0;
41 void Scare(int add_to_score, const char *reason) {
42 if (descr[0])
43 internal_strlcat(descr, "-", sizeof(descr));
44 internal_strlcat(descr, reason, sizeof(descr));
45 score += add_to_score;
47 int GetScore() const { return score; }
48 const char *GetDescription() const { return descr; }
49 void Print() const {
50 if (score && flags()->print_scariness)
51 Printf("SCARINESS: %d (%s)\n", score, descr);
53 static void PrintSimple(int score, const char *descr) {
54 ScarinessScoreBase SSB;
55 SSB.Clear();
56 SSB.Scare(score, descr);
57 SSB.Print();
60 private:
61 int score;
62 char descr[1024];
65 struct ScarinessScore : ScarinessScoreBase {
66 ScarinessScore() {
67 Clear();
71 } // namespace __asan
73 #endif // ASAN_SCARINESS_SCORE_H