public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Fix nullptr deref on HIR::Function
@ 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:444bb5b818315d278914df10dc1c5c650bae6946
commit 444bb5b818315d278914df10dc1c5c650bae6946
Author: Philip Herron <philip.herron@embecosm.com>
Date: Thu Jul 7 11:05:27 2022 +0100
Fix nullptr deref on HIR::Function
The clone interface on HIR::Functions can have an optional nullptr return
type which was always being derefed for the clone interface. This seems
to trigger when compiling with gcc-4.8 but not on modern GCC versions.
Diff:
---
gcc/rust/hir/tree/rust-hir-item.h | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index 109a5c238f2..1d451867753 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -1111,11 +1111,16 @@ public:
: VisItem (other), qualifiers (other.qualifiers),
function_name (other.function_name),
function_params (other.function_params),
- return_type (other.return_type->clone_type ()),
where_clause (other.where_clause),
function_body (other.function_body->clone_block_expr ()),
self (other.self), locus (other.locus)
{
+ // guard to prevent null dereference (always required)
+ if (other.return_type != nullptr)
+ return_type = other.return_type->clone_type ();
+ else
+ return_type = nullptr;
+
generic_params.reserve (other.generic_params.size ());
for (const auto &e : other.generic_params)
generic_params.push_back (e->clone_generic_param ());
@@ -1128,7 +1133,13 @@ public:
function_name = other.function_name;
qualifiers = other.qualifiers;
function_params = other.function_params;
- return_type = other.return_type->clone_type ();
+
+ // guard to prevent null dereference (always required)
+ if (other.return_type != nullptr)
+ return_type = other.return_type->clone_type ();
+ else
+ return_type = nullptr;
+
where_clause = other.where_clause;
function_body = other.function_body->clone_block_expr ();
locus = other.locus;
^ 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] Fix nullptr deref on HIR::Function 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).