diff options
author | Victor Stinner <vstinner@python.org> | 2020-03-25 18:27:36 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-25 18:27:36 (GMT) |
commit | 87d3b9db4ade1aa100ee6f065082cb7e85b8992f (patch) | |
tree | 85d17fff35bc28beb4a7c6e3a82276f2fa3760d5 /Objects/obmalloc.c | |
parent | ace018ca47c03ca699603341b12781b5329d2eaa (diff) | |
download | cpython-87d3b9db4ade1aa100ee6f065082cb7e85b8992f.zip cpython-87d3b9db4ade1aa100ee6f065082cb7e85b8992f.tar.gz cpython-87d3b9db4ade1aa100ee6f065082cb7e85b8992f.tar.bz2 |
bpo-39882: Add _Py_FatalErrorFormat() function (GH-19157)
Diffstat (limited to 'Objects/obmalloc.c')
-rw-r--r-- | Objects/obmalloc.c | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index 3b574bf..3f6f9cf 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -2361,26 +2361,22 @@ _PyMem_DebugRealloc(void *ctx, void *ptr, size_t nbytes) static void _PyMem_DebugCheckAddress(const char *func, char api, const void *p) { + assert(p != NULL); + const uint8_t *q = (const uint8_t *)p; - char msgbuf[64]; - const char *msg; size_t nbytes; const uint8_t *tail; int i; char id; - if (p == NULL) { - msg = "didn't expect a NULL pointer"; - goto error; - } - /* Check the API id */ id = (char)q[-SST]; if (id != api) { - msg = msgbuf; - snprintf(msgbuf, sizeof(msgbuf), "bad ID: Allocated using API '%c', verified using API '%c'", id, api); - msgbuf[sizeof(msgbuf)-1] = 0; - goto error; + _PyObject_DebugDumpAddress(p); + _Py_FatalErrorFormat(func, + "bad ID: Allocated using API '%c', " + "verified using API '%c'", + id, api); } /* Check the stuff at the start of p first: if there's underwrite @@ -2389,8 +2385,8 @@ _PyMem_DebugCheckAddress(const char *func, char api, const void *p) */ for (i = SST-1; i >= 1; --i) { if (*(q-i) != PYMEM_FORBIDDENBYTE) { - msg = "bad leading pad byte"; - goto error; + _PyObject_DebugDumpAddress(p); + _Py_FatalErrorFunc(func, "bad leading pad byte"); } } @@ -2398,16 +2394,10 @@ _PyMem_DebugCheckAddress(const char *func, char api, const void *p) tail = q + nbytes; for (i = 0; i < SST; ++i) { if (tail[i] != PYMEM_FORBIDDENBYTE) { - msg = "bad trailing pad byte"; - goto error; + _PyObject_DebugDumpAddress(p); + _Py_FatalErrorFunc(func, "bad trailing pad byte"); } } - - return; - -error: - _PyObject_DebugDumpAddress(p); - _Py_FatalErrorFunc(func, msg); } /* Display info to stderr about the memory block at p. */ |