mirror of
https://github.com/JakeHillion/drgn.git
synced 2024-12-22 09:13:06 +00:00
libdrgn: type: fix memcpy() undefined behavior
It's undefined behavior to pass NULL to memcpy() even if the length is
zero. See also commit a17215e984
("libdrgn: dwarf_index: fix memcpy()
undefined behavior").
Signed-off-by: Omar Sandoval <osandov@osandov.com>
This commit is contained in:
parent
7ca157316f
commit
c9dc7fd574
@ -1041,13 +1041,16 @@ drgn_type_with_byte_order_impl(struct drgn_type **type,
|
||||
drgn_type_program(*type));
|
||||
size_t num_enumerators =
|
||||
drgn_type_num_enumerators(*type);
|
||||
if (!drgn_type_enumerator_vector_reserve(&builder.enumerators,
|
||||
num_enumerators)) {
|
||||
drgn_enum_type_builder_deinit(&builder);
|
||||
return &drgn_enomem;
|
||||
if (num_enumerators) {
|
||||
if (!drgn_type_enumerator_vector_reserve(&builder.enumerators,
|
||||
num_enumerators)) {
|
||||
drgn_enum_type_builder_deinit(&builder);
|
||||
return &drgn_enomem;
|
||||
}
|
||||
memcpy(&builder.enumerators.data,
|
||||
drgn_type_enumerators(*type),
|
||||
num_enumerators * sizeof(struct drgn_type_enumerator));
|
||||
}
|
||||
memcpy(&builder.enumerators.data, drgn_type_enumerators(*type),
|
||||
num_enumerators * sizeof(struct drgn_type_enumerator));
|
||||
err = drgn_enum_type_create(&builder, drgn_type_tag(*type),
|
||||
compatible_type,
|
||||
drgn_type_language(*type), type);
|
||||
|
Loading…
Reference in New Issue
Block a user