Abstract

Rust is an emerging system programming language with attractive features in both memory safety and efficiency. However, its security is guaranteed with safe APIs only. Any usage of unsafe code is still possible to incur critical bugs. Since unsafe code offers much flexibility, such code is often unnecessarily used, especially by Rust beginners. To mitigate such risks, this paper proposes an intelligent approach to detect replaceable unsafe code and recommend its equivalent safe version to developers. To this end, we first collect a dataset of unsafe code snippets based on Rustdoc as our knowledge base, and then we employ the idea of siamese graph neural network to recognize similar code patterns for each unsafe code snippet written by developers and make recommendations accordingly. We have conducted an evaluation experiment with a dataset of real-world samples from GitHub, and results show that our approach can achieve an accuracy of 82.3%.

Full Text
Published version (Free)

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call