summaryrefslogtreecommitdiff
path: root/std/option.zc
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-19 22:48:04 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-19 22:48:04 +0000
commit23065ddf6ed0b3762dda5f5059888eb52b5c2415 (patch)
treeaec187b8211203081e8dacb07a5ce325eb348cc4 /std/option.zc
parent3af5dcf34d705cc52c1ffe5b85c2a90b5104e4c9 (diff)
Fixes related to memory safety. I will work more on this related to the stdlib.
Diffstat (limited to 'std/option.zc')
-rw-r--r--std/option.zc16
1 files changed, 15 insertions, 1 deletions
diff --git a/std/option.zc b/std/option.zc
index 5652bd7..11b4428 100644
--- a/std/option.zc
+++ b/std/option.zc
@@ -23,12 +23,26 @@ impl Option<T> {
return !self.is_some;
}
+ fn forget(self) {
+ memset(&self.val, 0, sizeof(T));
+ }
+
fn unwrap(self) -> T {
if (!self.is_some) {
!"Panic: unwrap called on None";
exit(1);
}
- return self.val;
+ var v = self.val;
+ memset(&self.val, 0, sizeof(T));
+ return v;
+ }
+
+ fn unwrap_ref(self) -> T* {
+ if (!self.is_some) {
+ !"Panic: unwrap_ref called on None";
+ exit(1);
+ }
+ return &self.val;
}
fn unwrap_or(self, def_val: T) -> T {