[gcc/devel/rust/master] HIR::TypeParam needs to be permissive of nullptr Type
Thomas Schwinge
tschwinge@gcc.gnu.org
Fri Jul 8 13:47:28 GMT 2022
https://gcc.gnu.org/g:31887c00fbdc7d607cf79b1042cb84d2c6db17e2
commit 31887c00fbdc7d607cf79b1042cb84d2c6db17e2
Author: Philip Herron <philip.herron@embecosm.com>
Date: Thu Jul 7 15:05:44 2022 +0100
HIR::TypeParam needs to be permissive of nullptr Type
Diff:
---
gcc/rust/hir/tree/rust-hir-item.h | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index 1d451867753..1fcecb828ad 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -75,9 +75,12 @@ public:
// Copy constructor uses clone
TypeParam (TypeParam const &other)
: GenericParam (other.mappings), outer_attr (other.outer_attr),
- type_representation (other.type_representation),
- type (other.type->clone_type ()), locus (other.locus)
+ type_representation (other.type_representation), locus (other.locus)
{
+ // guard to prevent null pointer dereference
+ if (other.type != nullptr)
+ type = other.type->clone_type ();
+
type_param_bounds.reserve (other.type_param_bounds.size ());
for (const auto &e : other.type_param_bounds)
type_param_bounds.push_back (e->clone_type_param_bound ());
@@ -87,19 +90,22 @@ public:
TypeParam &operator= (TypeParam const &other)
{
type_representation = other.type_representation;
- // type_param_bounds = other.type_param_bounds;
- type = other.type->clone_type ();
outer_attr = other.outer_attr;
locus = other.locus;
mappings = other.mappings;
+ // guard to prevent null pointer dereference
+ if (other.type != nullptr)
+ type = other.type->clone_type ();
+ else
+ type = nullptr;
+
type_param_bounds.reserve (other.type_param_bounds.size ());
for (const auto &e : other.type_param_bounds)
type_param_bounds.push_back (e->clone_type_param_bound ());
return *this;
}
-
// move constructors
TypeParam (TypeParam &&other) = default;
TypeParam &operator= (TypeParam &&other) = default;
More information about the Gcc-cvs
mailing list