MCPcopy Create free account
hub / github.com/FuzzAnything/PromptFuzz / init_fuzzable_list_var

Method init_fuzzable_list_var

src/program/transform.rs:409–460  ·  view source on GitHub ↗
(
        &mut self,
        decl_name: &str,
        ty: &str,
        shape: (usize, usize),
        ins_pos: usize,
        should_cast: bool,
    )

Source from the content-addressed store, hash-verified

407 }
408
409 fn init_fuzzable_list_var(
410 &mut self,
411 decl_name: &str,
412 ty: &str,
413 shape: (usize, usize),
414 ins_pos: usize,
415 should_cast: bool,
416 ) -> Result<()> {
417 let (row, col) = shape;
418 //let name = vd.get_var_decl_name();
419 // if is one dimensional array.
420 if col == 0 {
421 let mut array_init_stmts = format!("\n\t\t{decl_name} = {{");
422 let mut stmts = Vec::new();
423 for _i in 0..row {
424 let stmt = format!("fuzz_{ty}_{}", self.fuzzer_shim.get_init_id_inc());
425 stmts.push(stmt);
426 }
427 array_init_stmts.push_str(&stmts.join(","));
428 array_init_stmts.push_str("};");
429 self.fuzzer_shim
430 .append_fuzzer_stmt(array_init_stmts.clone());
431 self.seek_and_rewrite(ins_pos, 0, &array_init_stmts)?;
432 Ok(())
433 // else if two dimensional array.
434 } else {
435 let mut matrix_init_stmts = format!("\n\t\t{decl_name} = {{");
436 let mut row_stmts = Vec::new();
437 for _i in 0..row {
438 let mut col_stmts = Vec::new();
439 for _j in 0..col {
440 let stmt = format!("fuzz_{ty}_{}", self.fuzzer_shim.get_init_id_inc());
441 col_stmts.push(stmt)
442 }
443 let mut col_init = String::new();
444 if ty != "char" && should_cast {
445 let cast_stmt = format!("(const {ty} *)({ty} [{col}])");
446 col_init.push_str(&cast_stmt);
447 }
448 col_init.push('{');
449 col_init.push_str(&col_stmts.join(","));
450 col_init.push('}');
451 row_stmts.push(col_init);
452 }
453 matrix_init_stmts.push_str(&row_stmts.join(","));
454 matrix_init_stmts.push_str("};");
455 self.fuzzer_shim
456 .append_fuzzer_stmt(matrix_init_stmts.clone());
457 self.seek_and_rewrite(ins_pos, 0, &matrix_init_stmts)?;
458 Ok(())
459 }
460 }
461
462 /// Add the size_t constriant for the fuzzer input.
463 pub fn add_fuzzer_size_constraint(&mut self, size_stmt: &str) -> Result<()> {

Calls 3

append_fuzzer_stmtMethod · 0.80
seek_and_rewriteMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected