diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index eb513e84..8cb26e93 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -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"); diff --git a/tests/unit/out/unsafe/string_h.rs b/tests/unit/out/unsafe/string_h.rs index bd89b1f5..9c5faac7 100644 --- a/tests/unit/out/unsafe/string_h.rs +++ b/tests/unit/out/unsafe/string_h.rs @@ -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!( diff --git a/tests/unit/string_h.c b/tests/unit/string_h.c index 9202874d..3d47628b 100644 --- a/tests/unit/string_h.c +++ b/tests/unit/string_h.c @@ -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) {