Skip to content

Commit 3284cba

Browse files
committed
Fix char array initialization to use c_char
1 parent aee4da6 commit 3284cba

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1921,7 +1921,7 @@ bool Converter::VisitStringLiteral(clang::StringLiteral *expr) {
19211921
if (auto *arr_ty = ctx_.getAsConstantArrayType(curr_init_type_.back())) {
19221922
uint64_t arr_size = arr_ty->getSize().getZExtValue();
19231923
if (expr->getString().empty()) {
1924-
StrCat(std::format("[0u8; {}]", arr_size));
1924+
StrCat(std::format("[0 as ::core::ffi::c_char; {}]", arr_size));
19251925
return false;
19261926
}
19271927
uint64_t pad = arr_size > expr->getString().size()

cpp2rust/converter/models/converter_refcount.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ std::string ConverterRefCount::BuildFnAdapter(
211211
closure += std::format("a{}.reinterpret_cast::<{}>()", i,
212212
ConvertPointeeType(src_pty));
213213
} else if (src_pty->getPointeeType()->isCharType()) {
214-
closure += std::format("a{}.reinterpret_cast::<u8>()", i);
214+
closure += std::format("a{}.reinterpret_cast::<{}>()", i,
215+
ConvertPointeeType(src_pty));
215216
}
216217
} else {
217218
// UB: Incompatible types
@@ -1036,7 +1037,8 @@ bool ConverterRefCount::VisitStringLiteral(clang::StringLiteral *expr) {
10361037
if (auto *arr_ty = ctx_.getAsConstantArrayType(curr_init_type_.back())) {
10371038
uint64_t arr_size = arr_ty->getSize().getZExtValue();
10381039
if (expr->getString().empty()) {
1039-
StrCat(std::format("vec![0u8; {}].into_boxed_slice()", arr_size));
1040+
StrCat(std::format(
1041+
"vec![0 as ::core::ffi::c_char; {}].into_boxed_slice()", arr_size));
10401042
return false;
10411043
}
10421044
pad = arr_size > expr->getString().size()

0 commit comments

Comments
 (0)