Skip to content
Open
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
1 change: 1 addition & 0 deletions cpp2rust/converter/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3680,6 +3680,7 @@ void Converter::ConvertPointerOffset(clang::Expr *base, clang::Expr *idx,
PushParen neg_paren(*this, !is_addition);
{
PushParen inner(*this);
PushExprKind push(*this, ExprKind::RValue);
Convert(idx);
}
StrCat(keyword::kAs, "isize");
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/out/unsafe/string_h.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ pub unsafe fn test_strlen_5() {
as i32)
!= 0)
);
let buf: [libc::c_char; 8] = std::mem::transmute(*b"one\0two\0");
let mut first: *const libc::c_char = buf.as_ptr();
let mut second: *const libc::c_char =
(&buf[((libc::strlen(first)).wrapping_add(1_usize))] as *const libc::c_char);
assert!(
((((libc::strcmp(second, (c"two".as_ptr().cast_mut()).cast_const())) == (0)) as i32) != 0)
);
}
pub unsafe fn test_strcmp_6() {
assert!(
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/string_h.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ static void test_strlen(void) {
assert(strlen("") == 0);
assert(strlen("hello") == 5);
assert(strlen("hello world") == 11);
const char buf[] = "one\0two";
const char *first = buf;
const char *second = &buf[strlen(first) + 1];
assert(strcmp(second, "two") == 0);
}

static void test_strcmp(void) {
Expand Down
Loading