You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LLVM String means array of i8, which is not necessary NUL-terminated.
If, in Rust, we'll write "hello\0", it will result in the following LLVM IR:
@anon...212 = privateunnamed_addrglobal <{ [6 x i8] }> <{ [6 x i8] c"hello\00" }>, align1
This is a struct, where the only field is constant string (LLVMIsConstantString returns true).
Calling LLVMGetAsString for it returns a pointer to start of "hello\0\0" buffer AND the actual length of this string = 6
However, get_string_constant disregards the fact that the returned pointer may point to a string containing intermediate NULs such as "foo\0bar" thus it is invalid to turn in into a CStr (the part after \0 gets truncated).
This function should have the following signature:
pubfnget_string_constant(&self) -> Option<&[u8]>{letmut len = 0;let ptr = unsafe{LLVMGetAsString(self.as_value_ref(),&mut len)};if ptr.is_null(){None}else{// Returns [u8], because `cx.const_string` receives [u8].unsafe{Some(std::slice::from_raw_parts(ptr.cast(), len))}}}
The text was updated successfully, but these errors were encountered:
Describe the Bug
A clear and concise description of what the bug is.
get_string_constant calls LLVMGetAsString, and returns its result as CStr
This is not correct.
LLVM
String
means array of i8, which is not necessary NUL-terminated.If, in Rust, we'll write
"hello\0"
, it will result in the following LLVM IR:This is a struct, where the only field is
constant string
(LLVMIsConstantString
returns true).Calling
LLVMGetAsString
for it returns a pointer to start of "hello\0\0" buffer AND the actual length of this string = 6However,
get_string_constant
disregards the fact that the returned pointer may point to a string containing intermediate NULs such as "foo\0bar" thus it is invalid to turn in into a CStr (the part after \0 gets truncated).This function should have the following signature:
The text was updated successfully, but these errors were encountered: