Created
June 25, 2018 18:10
-
-
Save mssun/a44177380c172b4b4ed6213fddc151e5 to your computer and use it in GitHub Desktop.
A Rust unsafe code auto-translated by C2Rust with memory issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow ( dead_code )] | |
#![allow ( mutable_transmutes )] | |
#![allow ( non_camel_case_types )] | |
#![allow ( non_snake_case )] | |
#![allow ( non_upper_case_globals )] | |
#![allow ( unused_mut )] | |
extern crate libc; | |
#[no_mangle] | |
pub unsafe extern "C" fn insertion_sort(n: libc::c_int, p: *mut libc::c_int) | |
-> () { | |
let mut i: libc::c_int = 1i32; | |
while i <= n { | |
let tmp: libc::c_int = *p.offset(i as isize); | |
let mut j: libc::c_int = i; | |
while j > 0i32 && *p.offset((j - 1i32) as isize) > tmp { | |
*p.offset(j as isize) = *p.offset((j - 1i32) as isize); | |
j -= 1 | |
} | |
*p.offset(j as isize) = tmp; | |
i += 1 | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment