public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] libproc_macro: Custom Clone for Ident
@ 2023-04-06 21:32 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-04-06 21:32 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:acf5db71524e56aef7a0071be96299b976760454
commit acf5db71524e56aef7a0071be96299b976760454
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date: Tue Feb 21 12:18:41 2023 +0100
libproc_macro: Custom Clone for Ident
The internal Ident structure contains a foreign allocated byte array,
it's Clone trait cannot be derived automatically as the array would not
be cloned correctly, only the pointer. This would lead to use
after-free.
ChangeLog:
* librust/proc_macro/rust/bridge/ident.rs: Implement Clone for
Ident.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diff:
---
librust/proc_macro/rust/bridge/ident.rs | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/librust/proc_macro/rust/bridge/ident.rs b/librust/proc_macro/rust/bridge/ident.rs
index 1c08a003e02..dbfa649d923 100644
--- a/librust/proc_macro/rust/bridge/ident.rs
+++ b/librust/proc_macro/rust/bridge/ident.rs
@@ -7,10 +7,11 @@ extern "C" {
fn Ident__new(string: *const c_uchar, len: u64) -> Ident;
fn Ident__new_raw(string: *const c_uchar, len: u64) -> Ident;
fn Ident__drop(ident: *const Ident);
+ fn Ident__clone(ident: *const Ident) -> Ident;
}
#[repr(C)]
-#[derive(Clone, Debug)]
+#[derive(Debug)]
pub struct Ident {
pub(crate) is_raw: bool,
pub(crate) val: *const c_uchar,
@@ -59,3 +60,9 @@ impl fmt::Display for Ident {
)
}
}
+
+impl Clone for Ident {
+ fn clone(&self) -> Self {
+ unsafe { Ident__clone(self as *const Ident) }
+ }
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-04-06 21:32 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-06 21:32 [gcc/devel/rust/master] libproc_macro: Custom Clone for Ident 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).