* function.c (dump_stack_clash_frame_info): New function.
[official-gcc.git] / libsanitizer / asan / asan_scariness_score.h
blobd72fce69d6421722dd6ee9e22ed814910da670c9
1 //===-- asan_scariness_score.h ----------------------------------*- C++ -*-===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is a part of AddressSanitizer, an address sanity checker.
9 //
10 // Compute the level of scariness of the error message.
11 // Don't expect any deep science here, just a set of heuristics that suggest
12 // that e.g. 1-byte-read-global-buffer-overflow is less scary than
13 // 8-byte-write-stack-use-after-return.
15 // Every error report has one or more features, such as memory access size,
16 // type (read or write), type of accessed memory (e.g. free-d heap, or a global
17 // redzone), etc. Every such feature has an int score and a string description.
18 // The overall score is the sum of all feature scores and the description
19 // is a concatenation of feature descriptions.
20 // Examples:
21 // 17 (4-byte-read-heap-buffer-overflow)
22 // 65 (multi-byte-write-stack-use-after-return)
23 // 10 (null-deref)
25 //===----------------------------------------------------------------------===//
27 #ifndef ASAN_SCARINESS_SCORE_H
28 #define ASAN_SCARINESS_SCORE_H
30 #include "asan_flags.h"
31 #include "sanitizer_common/sanitizer_common.h"
32 #include "sanitizer_common/sanitizer_libc.h"
34 namespace __asan {
35 struct ScarinessScoreBase {
36 void Clear() {
37 descr[0] = 0;
38 score = 0;
40 void Scare(int add_to_score, const char *reason) {
41 if (descr[0])
42 internal_strlcat(descr, "-", sizeof(descr));
43 internal_strlcat(descr, reason, sizeof(descr));
44 score += add_to_score;
46 int GetScore() const { return score; }
47 const char *GetDescription() const { return descr; }
48 void Print() {
49 if (score && flags()->print_scariness)
50 Printf("SCARINESS: %d (%s)\n", score, descr);
52 static void PrintSimple(int score, const char *descr) {
53 ScarinessScoreBase SSB;
54 SSB.Clear();
55 SSB.Scare(score, descr);
56 SSB.Print();
59 private:
60 int score;
61 char descr[1024];
64 struct ScarinessScore : ScarinessScoreBase {
65 ScarinessScore() {
66 Clear();
70 } // namespace __asan
72 #endif // ASAN_SCARINESS_SCORE_H