MCPcopy Index your code
hub / github.com/NetHack/NetHack / nhrealloc

Function nhrealloc

src/alloc.c:169–202  ·  view source on GitHub ↗

re_alloc() with heap logging; we lack access to the old alloc size */

Source from the content-addressed store, hash-verified

167
168/* re_alloc() with heap logging; we lack access to the old alloc size */
169long *
170nhrealloc(
171 long *oldptr,
172 unsigned int newlth,
173 const char *file,
174 int line)
175{
176 long *newptr = re_alloc(oldptr, newlth);
177
178 if (!tried_heaplog)
179 heapmon_init();
180 if (heaplog) {
181 char op = '*'; /* assume realloc() will change size of previous
182 * allocation rather than make a new one */
183
184 if (newptr != oldptr) {
185 /* if oldptr wasn't Null, realloc() freed it */
186 if (oldptr)
187 (void) fprintf(heaplog, "%c%5s %s %4d %s\n", '<', "",
188 fmt_ptr((genericptr_t) oldptr), line, file);
189 op = '>'; /* new allocation rather than size-change of old one */
190 }
191 (void) fprintf(heaplog, "%c%5u %s %4d %s\n", op, newlth,
192 fmt_ptr((genericptr_t) newptr), line, file);
193 }
194 /* potential panic in re_alloc() was deferred til here;
195 "extend to": assume it won't ever fail if asked to shrink;
196 even if that assumption happens to be wrong, we lack access to
197 the old size so can't use alternate phrasing for that case */
198 if (newlth && !newptr)
199 panic("Cannot extend to %u bytes, line %d of %s", newlth, line, file);
200
201 return newptr;
202}
203
204void
205nhfree(genericptr_t ptr, const char *file, int line)

Callers

nothing calls this directly

Calls 5

re_allocFunction · 0.85
heapmon_initFunction · 0.85
fprintfFunction · 0.85
fmt_ptrFunction · 0.85
panicFunction · 0.50

Tested by

no test coverage detected