diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-07-07 11:05:27 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2022-07-08 12:39:26 +0100 |
commit | 444bb5b818315d278914df10dc1c5c650bae6946 (patch) | |
tree | bfdd66e989a5c953bcc71432b0891485daee16bf /gcc | |
parent | 33eb5c938ac41ff5e65c3a8d947d033b32d31ace (diff) | |
download | gcc-444bb5b818315d278914df10dc1c5c650bae6946.zip gcc-444bb5b818315d278914df10dc1c5c650bae6946.tar.gz gcc-444bb5b818315d278914df10dc1c5c650bae6946.tar.bz2 |
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-item.h | 15 |
1 files 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 109a5c2..1d45186 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; |