Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/bash/src/lib/malloc/watch.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | - | |||||||
2 | - | |||||||
3 | - | |||||||
4 | - | |||||||
5 | - | |||||||
6 | - | |||||||
7 | - | |||||||
8 | - | |||||||
9 | int _malloc_nwatch; | - | ||||||
10 | static void * _malloc_watch_list[32]; | - | ||||||
11 | - | |||||||
12 | static void | - | ||||||
13 | watch_warn (addr, file, line, type, data) | - | ||||||
14 | void * addr; | - | ||||||
15 | const char *file; | - | ||||||
16 | int line, type; | - | ||||||
17 | unsigned long data; | - | ||||||
18 | { | - | ||||||
19 | char *tag; | - | ||||||
20 | - | |||||||
21 | if (type == 0x01
| 0 | ||||||
22 | tag = "allocated"; never executed: tag = "allocated"; | 0 | ||||||
23 | else if (type == 0x02
| 0 | ||||||
24 | tag = "freed"; never executed: tag = "freed"; | 0 | ||||||
25 | else if (type == 0x04
| 0 | ||||||
26 | tag = "requesting resize"; never executed: tag = "requesting resize"; | 0 | ||||||
27 | else if (type == 0x08
| 0 | ||||||
28 | tag = "just resized"; never executed: tag = "just resized"; | 0 | ||||||
29 | else | - | ||||||
30 | tag = "bug: unknown operation"; never executed: tag = "bug: unknown operation"; | 0 | ||||||
31 | - | |||||||
32 | fprintf ( | - | ||||||
33 | stderr | - | ||||||
34 | , "malloc: watch alert: %p %s ", addr, tag); | - | ||||||
35 | if (data != (unsigned long)-1
| 0 | ||||||
36 | fprintf ( never executed: fprintf ( stderr , "(size %lu) ", data); | 0 | ||||||
37 | stderr never executed: fprintf ( stderr , "(size %lu) ", data); | 0 | ||||||
38 | , "(size %lu) ", data); never executed: fprintf ( stderr , "(size %lu) ", data); | 0 | ||||||
39 | fprintf ( | - | ||||||
40 | stderr | - | ||||||
41 | , "from '%s:%d'\n", file ? file : "unknown", line); | - | ||||||
42 | } never executed: end of block | 0 | ||||||
43 | - | |||||||
44 | void | - | ||||||
45 | _malloc_ckwatch (addr, file, line, type, data) | - | ||||||
46 | void * addr; | - | ||||||
47 | const char *file; | - | ||||||
48 | int line, type; | - | ||||||
49 | unsigned long data; | - | ||||||
50 | { | - | ||||||
51 | register int i; | - | ||||||
52 | - | |||||||
53 | for (i = _malloc_nwatch - 1; i >= 0
| 0 | ||||||
54 | { | - | ||||||
55 | if (_malloc_watch_list[i] == addr
| 0 | ||||||
56 | { | - | ||||||
57 | watch_warn (addr, file, line, type, data); | - | ||||||
58 | return; never executed: return; | 0 | ||||||
59 | } | - | ||||||
60 | } never executed: end of block | 0 | ||||||
61 | } never executed: end of block | 0 | ||||||
62 | - | |||||||
63 | - | |||||||
64 | void * | - | ||||||
65 | malloc_watch (addr) | - | ||||||
66 | void * addr; | - | ||||||
67 | { | - | ||||||
68 | register int i; | - | ||||||
69 | void * ret; | - | ||||||
70 | - | |||||||
71 | if (addr == 0
| 0 | ||||||
72 | return never executed: addr;return addr; never executed: return addr; | 0 | ||||||
73 | ret = (void *)0; | - | ||||||
74 | - | |||||||
75 | - | |||||||
76 | for (i = _malloc_nwatch - 1; i >= 0
| 0 | ||||||
77 | { | - | ||||||
78 | if (_malloc_watch_list[i] == addr
| 0 | ||||||
79 | break; never executed: break; | 0 | ||||||
80 | } never executed: end of block | 0 | ||||||
81 | if (i < 0
| 0 | ||||||
82 | { | - | ||||||
83 | if (_malloc_nwatch == 32
| 0 | ||||||
84 | { | - | ||||||
85 | ret = _malloc_watch_list[0]; | - | ||||||
86 | _malloc_nwatch--; | - | ||||||
87 | for (i = 0; i < _malloc_nwatch
| 0 | ||||||
88 | _malloc_watch_list[i] = _malloc_watch_list[i+1]; never executed: _malloc_watch_list[i] = _malloc_watch_list[i+1]; | 0 | ||||||
89 | } never executed: end of block | 0 | ||||||
90 | _malloc_watch_list[_malloc_nwatch++] = addr; | - | ||||||
91 | } never executed: end of block | 0 | ||||||
92 | - | |||||||
93 | - | |||||||
94 | return never executed: ret;return ret; never executed: return ret; | 0 | ||||||
95 | } | - | ||||||
96 | - | |||||||
97 | - | |||||||
98 | - | |||||||
99 | - | |||||||
100 | void * | - | ||||||
101 | malloc_unwatch (addr) | - | ||||||
102 | void * addr; | - | ||||||
103 | { | - | ||||||
104 | - | |||||||
105 | register int i; | - | ||||||
106 | - | |||||||
107 | if (addr == 0
| 0 | ||||||
108 | { | - | ||||||
109 | for (i = 0; i < _malloc_nwatch
| 0 | ||||||
110 | _malloc_watch_list[i] = (void *)0; never executed: _malloc_watch_list[i] = (void *)0; | 0 | ||||||
111 | _malloc_nwatch = 0; | - | ||||||
112 | return never executed: ((void *)0);return ((void *)0); never executed: return ((void *)0); | 0 | ||||||
113 | } | - | ||||||
114 | else | - | ||||||
115 | { | - | ||||||
116 | for (i = 0; i < _malloc_nwatch
| 0 | ||||||
117 | { | - | ||||||
118 | if (_malloc_watch_list[i] == addr
| 0 | ||||||
119 | break; never executed: break; | 0 | ||||||
120 | } never executed: end of block | 0 | ||||||
121 | if (i == _malloc_nwatch
| 0 | ||||||
122 | return never executed: ((void *)0);return ((void *)0); never executed: return ((void *)0); | 0 | ||||||
123 | - | |||||||
124 | _malloc_nwatch--; | - | ||||||
125 | for ( ; i < _malloc_nwatch
| 0 | ||||||
126 | _malloc_watch_list[i] = _malloc_watch_list[i+1]; never executed: _malloc_watch_list[i] = _malloc_watch_list[i+1]; | 0 | ||||||
127 | return never executed: addr;return addr; never executed: return addr; | 0 | ||||||
128 | } | - | ||||||
129 | - | |||||||
130 | - | |||||||
131 | - | |||||||
132 | } | - | ||||||
Switch to Source code | Preprocessed file |