aboutsummaryrefslogtreecommitdiff
path: root/lib/xixanta/src/node.rs
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2025-09-03 19:08:05 +0200
committerMiquel Sabaté Solà <mikisabate@gmail.com>2025-09-03 20:45:54 +0200
commit9dcbf460ff692c049e4d327afcbdbc39ba4e8c65 (patch)
tree1d96e2bccc566a3092768da691e7ca47881880de /lib/xixanta/src/node.rs
parenta3989fb9c5424f2f93c67669102ee8cb61303c24 (diff)
downloadtools.nes-9dcbf460ff692c049e4d327afcbdbc39ba4e8c65.tar.gz
tools.nes-9dcbf460ff692c049e4d327afcbdbc39ba4e8c65.zip
Validate that memory access is done via variables
The address sanitizer is now able to detect whenever in an instruction a memory access is done without using variables. This is now detected for all instructions except for branching, which falls outside of this scope. Moreover, simple arithmetics is allowed and bounds are checked for simple cases. That being said, more involved bound checks should be done with other tools (e.g. emulators). Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib/xixanta/src/node.rs')
-rw-r--r--lib/xixanta/src/node.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/xixanta/src/node.rs b/lib/xixanta/src/node.rs
index 7cfc107..465dde2 100644
--- a/lib/xixanta/src/node.rs
+++ b/lib/xixanta/src/node.rs
@@ -1,5 +1,13 @@
use std::fmt;
+/// Returns true if this String follows the naming
+/// conventions as expected by the address sanitizer.
+pub fn is_asan_friendly_name(string: &str) -> bool {
+ let name = string.split("::").last().unwrap_or("");
+
+ name.starts_with("zp_") || name.starts_with("wr_") || name.starts_with("m_")
+}
+
/// A Positioned String. That is, a String which also has information on the
/// line number and the column range.
#[derive(Debug, Default, Clone, PartialEq)]
@@ -456,3 +464,25 @@ impl PNode {
}
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn is_asan_friendly_name_test() {
+ let tests = vec![
+ ("zp_name", true),
+ ("name", false),
+ ("Scope::zp_name", true),
+ ("Scope::Inner::zp_good", true),
+ ("Scope::Inner::bad", false),
+ ];
+
+ for (name, expect) in tests {
+ let string = String::from(name);
+
+ assert_eq!(is_asan_friendly_name(&string), expect);
+ }
+ }
+}