public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] HIR::TypeParam needs to be permissive of nullptr Type
@ 2022-07-08 13:47 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-07-08 13:47 UTC (permalink / raw)
  To: gcc-cvs

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;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-08 13:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-08 13:47 [gcc/devel/rust/master] HIR::TypeParam needs to be permissive of nullptr Type Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).