Skip to content

Commit a9c50e7

Browse files
authored
Add safe cstring rules (#250)
1 parent 2b05463 commit a9c50e7

18 files changed

Lines changed: 2668 additions & 71 deletions

File tree

‎cpp2rust/converter/models/converter_refcount.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,9 @@ bool ConverterRefCount::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) {
11691169

11701170
if (expr->getCastKind() == clang::CastKind::CK_BitCast) {
11711171
if (expr->getType()->isVoidPointerType()) {
1172+
if (sub_expr->getType()->isVoidPointerType()) {
1173+
return Convert(sub_expr);
1174+
}
11721175
PushConversionKind push(*this, ConversionKind::Unboxed);
11731176
if (sub_expr->getType()->isPointerType() &&
11741177
sub_expr->getType()->getPointeeType()->isArrayType()) {

‎libcc2rs/src/rc.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,16 @@ impl Ptr<u8> {
10101010

10111011
#[allow(clippy::explicit_counter_loop)]
10121012
pub fn memcpy(&self, src: &Self, len: usize) {
1013+
if *self > *src {
1014+
let mut dst = self.offset(len);
1015+
let mut s = src.offset(len);
1016+
for _ in 0..len {
1017+
dst -= 1;
1018+
s -= 1;
1019+
dst.write(s.read());
1020+
}
1021+
return;
1022+
}
10131023
let mut dst = self.clone();
10141024
let mut i: usize = 0;
10151025
for value in src {

‎rule-preprocessor/src/semantic.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,10 @@ impl<'a, 'tcx> AstVisitor<'a, 'tcx> {
406406
rustc_hir::ExprKind::Lit(_)
407407
| rustc_hir::ExprKind::Path(_)
408408
| rustc_hir::ExprKind::Ret(None)
409-
| rustc_hir::ExprKind::Break(_, _)
409+
| rustc_hir::ExprKind::Break(_, None)
410410
| rustc_hir::ExprKind::Continue(_) => {}
411411

412-
rustc_hir::ExprKind::Ret(Some(e)) => {
412+
rustc_hir::ExprKind::Ret(Some(e)) | rustc_hir::ExprKind::Break(_, Some(e)) => {
413413
self.visit_expr(e, Access::Read);
414414
}
415415

0 commit comments

Comments
 (0)