summaryrefslogtreecommitdiff
path: root/utils/coverity/model.c
blob: d0a3708b65bfe51ab6980cbb644454ac74d4b9c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* Coverity Scan model
 * This is a modeling file for Coverity Scan. Modeling helps to avoid false
 * positives.
 *
 * - A model file can't import any header files.  Some built-in primitives are
 *   available but not wchar_t, NULL etc.
 * - Modeling doesn't need full structs and typedefs. Rudimentary structs
 *   and similar types are sufficient.
 * - An uninitialized local variable signifies that the variable could be
 *   any value.
 *
 * The model file must be uploaded by an admin in the analysis settings of
 * http://scan.coverity.com/projects/1919
 */

#define NULL ((void*)0)
#define assert(x) if (!(x)) __coverity_panic__();

/* type decls */
typedef struct {} va_list;

/* glibc functions */
void *malloc (size_t);
void *calloc (size_t, size_t);
void *realloc (void *, size_t);
void free (void *);

/* rts allocation functions */

void* stgMallocBytes(int n, char *msg)
{
  void *mem;
  __coverity_negative_sink__((size_t)n);
  mem = malloc((size_t)n);
  assert(mem != NULL);
  return mem;
}

void* stgReallocBytes(void *p, int n, char *msg)
{
  void *mem;
  __coverity_negative_sink__((size_t)n);

  /* man 3 realloc: if p == NULL, then realloc is equivalent to malloc() */
  if (p == NULL) {
    mem = malloc((size_t)n);
    assert(mem != NULL);
    return mem;
  }

  /* man 3 realloc: if n == 0, then realloc is equivalent to free() */
  if (n == 0) {
    free(p);
    return NULL;
  } else {
    mem = realloc(p, (size_t)n);
    assert(mem != NULL);
    return mem;
  }
}

void* stgCallocBytes(int n, int m, char *msg)
{
  void *mem;
  __coverity_negative_sink__((size_t)n);
  __coverity_negative_sink__((size_t)m);
  mem = calloc(n, m);
  assert(mem != NULL);
  return mem;
}

void stgFree(void* p)
{
  free(p);
}

/* Kill paths */

void stg_exit(int n)
{
  __coverity_panic__();
}

void shutdownThread(void)
{
  __coverity_panic__();
}

void shutdownHaskellAndExit(int exitCode, int fastExit)
{
  __coverity_panic__();
}

void shutdownHaskellAndSignal(int sig, int fastExit)
{
  __coverity_panic__();
}

void _assertFail(const char *filename, unsigned int linenum)
{
  __coverity_panic__();
}

void barf(const char *s, ...)
{
  __coverity_panic__();
}

void vbarf(const char *s, va_list ap)
{
  __coverity_panic__();
}