make up a variable for this call's string arg.
(
&mut self,
call: &Node,
array_pos: usize,
constraint: &Option<Constraint>,
)
| 228 | |
| 229 | /// make up a variable for this call's string arg. |
| 230 | fn makeup_call_string_arg( |
| 231 | &mut self, |
| 232 | call: &Node, |
| 233 | array_pos: usize, |
| 234 | constraint: &Option<Constraint>, |
| 235 | ) -> Result<()> { |
| 236 | let init_id = self.fuzzer_shim.get_init_id_inc(); |
| 237 | let fuzz_str = format!("fuzz_str_{}", init_id); |
| 238 | if let Some(constraint) = constraint { |
| 239 | match constraint { |
| 240 | Constraint::ArrayLen((array_pos, integer_pos)) => { |
| 241 | // format the declaration name and type of this array var. |
| 242 | let arg_ty = get_func_arg_decl_type(call, *integer_pos); |
| 243 | let fuzz_size = if arg_ty.contains('*') { |
| 244 | format!("static_cast<{arg_ty}>(&fuzz_str_sz_{init_id})") |
| 245 | } else { |
| 246 | format!("static_cast<{arg_ty}>(fuzz_str_sz_{init_id})") |
| 247 | }; |
| 248 | |
| 249 | if integer_pos > array_pos { |
| 250 | self.change_call_arg(call, *integer_pos, &fuzz_size)?; |
| 251 | self.change_call_arg(call, *array_pos, &fuzz_str)?; |
| 252 | } else { |
| 253 | self.change_call_arg(call, *array_pos, &fuzz_str)?; |
| 254 | self.change_call_arg(call, *integer_pos, &fuzz_size)?; |
| 255 | } |
| 256 | } |
| 257 | Constraint::ArrayIndex((array_pos, integer_pos)) => { |
| 258 | // format the declaration name and type of this array var. |
| 259 | let arg_ty = get_func_arg_decl_type(call, *integer_pos); |
| 260 | let index_stmt = format!("\n\tFDPGetRandomInteger({arg_ty}, fuzz_str_idx_{init_id}, fuzz_str_sz_{init_id});"); |
| 261 | let fuzz_size = if arg_ty.contains('*') { |
| 262 | format!("static_cast<{arg_ty}>(&fuzz_str_idx_{init_id})") |
| 263 | } else { |
| 264 | format!("static_cast<{arg_ty}>(fuzz_str_idx_{init_id})") |
| 265 | }; |
| 266 | |
| 267 | if integer_pos > array_pos { |
| 268 | self.change_call_arg(call, *integer_pos, &fuzz_size)?; |
| 269 | self.change_call_arg(call, *array_pos, &fuzz_str)?; |
| 270 | } else { |
| 271 | self.change_call_arg(call, *array_pos, &fuzz_str)?; |
| 272 | self.change_call_arg(call, *integer_pos, &fuzz_size)?; |
| 273 | } |
| 274 | let ins_pos = get_fuzzer_shim_end_loc(&self.src_file)?; |
| 275 | self.seek_and_rewrite(ins_pos, 0, &index_stmt)?; |
| 276 | } |
| 277 | _ => unreachable!(), |
| 278 | } |
| 279 | } else { |
| 280 | self.change_call_arg(call, array_pos, &fuzz_str)?; |
| 281 | } |
| 282 | Ok(()) |
| 283 | } |
| 284 | |
| 285 | fn makeup_call_integer_arg(&mut self, call: &Node, arg_pos: usize, ty: &str) -> Result<()> { |
| 286 | let c_ty_name = match ty { |
no test coverage detected