diff options
Diffstat (limited to 'gdb/python/py-inferior.c')
-rw-r--r-- | gdb/python/py-inferior.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 795ac65..a1042ee 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -555,6 +555,18 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw) || get_addr_from_python (length_obj, &length) < 0) return NULL; + if (length == 0) + { + PyErr_SetString (PyExc_ValueError, + _("Argument 'count' should be greater than zero")); + return NULL; + } + + void *p = malloc (length); + if (p == nullptr) + return PyErr_NoMemory (); + buffer.reset ((gdb_byte *) p); + try { /* Use this scoped-restore because we want to be able to read @@ -562,8 +574,6 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw) scoped_restore_current_inferior_for_memory restore_inferior (inf->inferior); - buffer.reset ((gdb_byte *) xmalloc (length)); - read_memory (addr, buffer.get (), length); } catch (const gdb_exception &except) |