Remove inappropriate .to_c_str() in C_cstr()
LLVMConstStringInContext() doesn't need a null-terminated string. It takes a length instead. Using .to_c_str() here triggers an ICE whenever the string literal embeds a null, as in "\x00".
This commit is contained in:
parent
f744cf157e
commit
5ca4cdc7b8
@ -36,7 +36,7 @@ use std::c_str::ToCStr;
|
||||
use std::cast::transmute;
|
||||
use std::cast;
|
||||
use std::hashmap::{HashMap};
|
||||
use std::libc::{c_uint, c_longlong, c_ulonglong};
|
||||
use std::libc::{c_uint, c_longlong, c_ulonglong, c_char};
|
||||
use std::vec;
|
||||
use syntax::ast::ident;
|
||||
use syntax::ast_map::{path, path_elt};
|
||||
@ -760,8 +760,8 @@ pub fn C_cstr(cx: &mut CrateContext, s: @str) -> ValueRef {
|
||||
None => ()
|
||||
}
|
||||
|
||||
let sc = do s.with_c_str |buf| {
|
||||
llvm::LLVMConstStringInContext(cx.llcx, buf, s.len() as c_uint, False)
|
||||
let sc = do s.as_imm_buf |buf, buflen| {
|
||||
llvm::LLVMConstStringInContext(cx.llcx, buf as *c_char, buflen as c_uint, False)
|
||||
};
|
||||
|
||||
let gsym = token::gensym("str");
|
||||
|
@ -265,7 +265,7 @@ pub fn trans_lit_str(bcx: @mut Block,
|
||||
Ignore => bcx,
|
||||
SaveIn(lldest) => {
|
||||
unsafe {
|
||||
let bytes = str_lit.len(); // count null-terminator too
|
||||
let bytes = str_lit.len();
|
||||
let llbytes = C_uint(bcx.ccx(), bytes);
|
||||
let llcstr = C_cstr(bcx.ccx(), str_lit);
|
||||
let llcstr = llvm::LLVMConstPointerCast(llcstr, Type::i8p().to_ref());
|
||||
|
Loading…
Reference in New Issue
Block a user