mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-12-19 01:19:41 +08:00
Clean up 0-length handling in gdbpy_create_lazy_string_object
gdbpy_create_lazy_string_object will throw an exception if you pass it a NULL pointer without also setting length=0 -- the default, length==-1, will fail. This seems bizarre. Furthermore, it doesn't make sense to do this check for array types, as an array can have a zero length. This patch cleans up the check and makes it specific to TYPE_CODE_PTR.
This commit is contained in:
@@ -182,14 +182,6 @@ gdbpy_create_lazy_string_object (CORE_ADDR address, long length,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (address == 0 && length != 0)
|
||||
{
|
||||
PyErr_SetString (gdbpy_gdb_memory_error,
|
||||
_("Cannot create a lazy string with address 0x0, " \
|
||||
"and a non-zero length."));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!type)
|
||||
{
|
||||
PyErr_SetString (PyExc_RuntimeError,
|
||||
@@ -216,6 +208,23 @@ gdbpy_create_lazy_string_object (CORE_ADDR address, long length,
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case TYPE_CODE_PTR:
|
||||
if (address == 0)
|
||||
{
|
||||
if (length > 0)
|
||||
{
|
||||
PyErr_SetString (gdbpy_gdb_memory_error,
|
||||
_("Cannot create a lazy string with address 0x0, " \
|
||||
"and a non-zero length."));
|
||||
return nullptr;
|
||||
}
|
||||
length = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
gdb_assert_not_reached ("invalid type in gdbpy_create_lazy_string_object");
|
||||
}
|
||||
|
||||
str_obj = PyObject_New (lazy_string_object, &lazy_string_object_type);
|
||||
|
||||
Reference in New Issue
Block a user