OpenCoverage

watch.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/lib/malloc/watch.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9int _malloc_nwatch;-
10static void * _malloc_watch_list[32];-
11-
12static void-
13watch_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
type == 0x01Description
TRUEnever evaluated
FALSEnever evaluated
)
0
22 tag = "allocated";
never executed: tag = "allocated";
0
23 else if (type == 0x02
type == 0x02Description
TRUEnever evaluated
FALSEnever evaluated
)
0
24 tag = "freed";
never executed: tag = "freed";
0
25 else if (type == 0x04
type == 0x04Description
TRUEnever evaluated
FALSEnever evaluated
)
0
26 tag = "requesting resize";
never executed: tag = "requesting resize";
0
27 else if (type == 0x08
type == 0x08Description
TRUEnever evaluated
FALSEnever evaluated
)
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
data != (unsigned long)-1Description
TRUEnever evaluated
FALSEnever evaluated
)
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-
44void-
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
i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
; i--)
0
54 {-
55 if (_malloc_watch_list[i] == addr
_malloc_watch_list[i] == addrDescription
TRUEnever evaluated
FALSEnever evaluated
)
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-
64void *-
65malloc_watch (addr)-
66 void * addr;-
67{-
68 register int i;-
69 void * ret;-
70-
71 if (addr == 0
addr == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
72 return
never executed: return addr;
addr;
never executed: return addr;
0
73 ret = (void *)0;-
74-
75-
76 for (i = _malloc_nwatch - 1; i >= 0
i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
; i--)
0
77 {-
78 if (_malloc_watch_list[i] == addr
_malloc_watch_list[i] == addrDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
79 break;
never executed: break;
0
80 }
never executed: end of block
0
81 if (i < 0
i < 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
82 {-
83 if (_malloc_nwatch == 32
_malloc_nwatch == 32Description
TRUEnever evaluated
FALSEnever evaluated
)
0
84 {-
85 ret = _malloc_watch_list[0];-
86 _malloc_nwatch--;-
87 for (i = 0; i < _malloc_nwatch
i < _malloc_nwatchDescription
TRUEnever evaluated
FALSEnever evaluated
; i++)
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: return ret;
ret;
never executed: return ret;
0
95}-
96-
97-
98-
99-
100void *-
101malloc_unwatch (addr)-
102 void * addr;-
103{-
104-
105 register int i;-
106-
107 if (addr == 0
addr == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
108 {-
109 for (i = 0; i < _malloc_nwatch
i < _malloc_nwatchDescription
TRUEnever evaluated
FALSEnever evaluated
; i++)
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: return ((void *)0);
((void *)0);
never executed: return ((void *)0);
0
113 }-
114 else-
115 {-
116 for (i = 0; i < _malloc_nwatch
i < _malloc_nwatchDescription
TRUEnever evaluated
FALSEnever evaluated
; i++)
0
117 {-
118 if (_malloc_watch_list[i] == addr
_malloc_watch_list[i] == addrDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
119 break;
never executed: break;
0
120 }
never executed: end of block
0
121 if (i == _malloc_nwatch
i == _malloc_nwatchDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
122 return
never executed: return ((void *)0);
((void *)0);
never executed: return ((void *)0);
0
123-
124 _malloc_nwatch--;-
125 for ( ; i < _malloc_nwatch
i < _malloc_nwatchDescription
TRUEnever evaluated
FALSEnever evaluated
; i++)
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: return addr;
addr;
never executed: return addr;
0
128 }-
129-
130-
131-
132}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.1.2