Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions rules/arpa_inet/ir_unsafe.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,53 @@
"return_type": {
"type": "u16"
}
},
"f3": {
"body": [
{
"text": "u16::to_be("
},
{
"placeholder": {
"arg": 0,
"access": "read"
}
},
{
"text": ")"
}
],
"params": {
"a0": {
"type": "u16"
}
},
"return_type": {
"type": "u16"
}
},
"f4": {
"body": [
{
"text": "u32::to_be("
},
{
"placeholder": {
"arg": 0,
"access": "read"
}
},
{
"text": ")"
}
],
"params": {
"a0": {
"type": "u32"
}
},
"return_type": {
"type": "u32"
}
}
}
2 changes: 2 additions & 0 deletions rules/arpa_inet/src.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@

uint32_t f1(uint32_t x) { return ntohl(x); }
uint16_t f2(uint16_t x) { return ntohs(x); }
uint16_t f3(uint16_t x) { return htons(x); }
uint32_t f4(uint32_t x) { return htonl(x); }
6 changes: 6 additions & 0 deletions rules/arpa_inet/tgt_unsafe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ unsafe fn f1(a0: u32) -> u32 {
unsafe fn f2(a0: u16) -> u16 {
u16::from_be(a0)
}
unsafe fn f3(a0: u16) -> u16 {
u16::to_be(a0)
}
unsafe fn f4(a0: u32) -> u32 {
u32::to_be(a0)
}
133 changes: 133 additions & 0 deletions rules/cstdlib/ir_unsafe.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,138 @@
"return_type": {
"type": "i32"
}
},
"f8": {
"body": [
{
"text": "libc::bsearch(\n "
},
{
"placeholder": {
"arg": 0,
"access": "read"
}
},
{
"text": ",\n "
},
{
"placeholder": {
"arg": 1,
"access": "read"
}
},
{
"text": ",\n "
},
{
"placeholder": {
"arg": 2,
"access": "read"
}
},
{
"text": " as ::libc::size_t,\n "
},
{
"placeholder": {
"arg": 3,
"access": "read"
}
},
{
"text": " as ::libc::size_t,\n Some(std::mem::transmute::<\n *const (),\n unsafe extern \"C\" fn(*const ::libc::c_void, *const ::libc::c_void) -> i32,\n >("
},
{
"placeholder": {
"arg": 4,
"access": "read"
}
},
{
"text": " as *const ())),\n )"
}
],
"params": {
"a0": {
"type": "*const ::libc::c_void",
"is_unsafe_pointer": true
},
"a1": {
"type": "*const ::libc::c_void",
"is_unsafe_pointer": true
},
"a2": {
"type": "u64"
},
"a3": {
"type": "u64"
},
"a4": {
"type": "unsafe fn(*const ::libc::c_void, *const ::libc::c_void) -> i32"
}
},
"return_type": {
"type": "*mut ::libc::c_void",
"is_unsafe_pointer": true
}
},
"f9": {
"body": [
{
"text": "libc::qsort(\n "
},
{
"placeholder": {
"arg": 0,
"access": "read"
}
},
{
"text": ",\n "
},
{
"placeholder": {
"arg": 1,
"access": "read"
}
},
{
"text": " as ::libc::size_t,\n "
},
{
"placeholder": {
"arg": 2,
"access": "read"
}
},
{
"text": " as ::libc::size_t,\n Some(std::mem::transmute::<\n *const (),\n unsafe extern \"C\" fn(*const ::libc::c_void, *const ::libc::c_void) -> i32,\n >("
},
{
"placeholder": {
"arg": 3,
"access": "read"
}
},
{
"text": " as *const ())),\n )"
}
],
"params": {
"a0": {
"type": "*mut ::libc::c_void",
"is_unsafe_pointer": true
},
"a1": {
"type": "u64"
},
"a2": {
"type": "u64"
},
"a3": {
"type": "unsafe fn(*const ::libc::c_void, *const ::libc::c_void) -> i32"
}
}
}
}
10 changes: 10 additions & 0 deletions rules/cstdlib/src.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,13 @@ char *f6(const char *name) { return getenv(name); }
int f7(const char *name, const char *value, int overwrite) {
return setenv(name, value, overwrite);
}

void *f8(const void *key, const void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *)) {
return bsearch(key, base, nmemb, size, compar);
}

void f9(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *)) {
return qsort(base, nmemb, size, compar);
}
36 changes: 36 additions & 0 deletions rules/cstdlib/tgt_unsafe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,39 @@ unsafe fn f6(a0: *const u8) -> *mut u8 {
unsafe fn f7(a0: *const u8, a1: *const u8, a2: i32) -> i32 {
libc::setenv(a0 as *const i8, a1 as *const i8, a2)
}

unsafe fn f8(
a0: *const ::libc::c_void,
a1: *const ::libc::c_void,
a2: u64,
a3: u64,
a4: unsafe fn(*const ::libc::c_void, *const ::libc::c_void) -> i32,
) -> *mut ::libc::c_void {
libc::bsearch(
a0,
a1,
a2 as ::libc::size_t,
a3 as ::libc::size_t,
Some(std::mem::transmute::<
*const (),
unsafe extern "C" fn(*const ::libc::c_void, *const ::libc::c_void) -> i32,
>(a4 as *const ())),
)
}

unsafe fn f9(
a0: *mut ::libc::c_void,
a1: u64,
a2: u64,
a3: unsafe fn(*const ::libc::c_void, *const ::libc::c_void) -> i32,
) {
libc::qsort(
a0,
a1 as ::libc::size_t,
a2 as ::libc::size_t,
Some(std::mem::transmute::<
*const (),
unsafe extern "C" fn(*const ::libc::c_void, *const ::libc::c_void) -> i32,
>(a3 as *const ())),
)
}
Loading
Loading