Skip to content

Instantly share code, notes, and snippets.

@mssun
Created June 25, 2018 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mssun/a44177380c172b4b4ed6213fddc151e5 to your computer and use it in GitHub Desktop.
Save mssun/a44177380c172b4b4ed6213fddc151e5 to your computer and use it in GitHub Desktop.
A Rust unsafe code auto-translated by C2Rust with memory issue
#![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