Browse Source

Use references where needed only

All cases where found by cargo-clippy
Jan-Erik Rediger 8 năm trước cách đây
mục cha
commit
5eef1e3f27
4 tập tin đã thay đổi với 12 bổ sung12 xóa
  1. 2 2
      README.md
  2. 2 2
      examples/load_elf.rs
  3. 3 3
      examples/to_json.rs
  4. 5 5
      tests/misc.rs

+ 2 - 2
README.md

@@ -380,7 +380,7 @@ fn main() {
         None => panic!("Failed to look up .classifier section"),
     };
 
-    let ref prog = &text_scn.data;
+    let prog = &text_scn.data;
 
     // This is our data: a real packet, starting with Ethernet header
     let mut packet = vec![
@@ -409,7 +409,7 @@ fn main() {
     // We must provide the offsets at which the pointers to packet data start
     // and end must be stored: these are the offsets at which the program will
     // load the packet data from the metadata buffer.
-    let mut vm = rbpf::EbpfVmFixedMbuff::new(&prog, 0x40, 0x50);
+    let mut vm = rbpf::EbpfVmFixedMbuff::new(prog, 0x40, 0x50);
 
     // We register a helper function, that can be called by the program, into
     // the VM.

+ 2 - 2
examples/load_elf.rs

@@ -65,7 +65,7 @@ fn main() {
         None => panic!("Failed to look up .classifier section"),
     };
 
-    let ref prog = &text_scn.data;
+    let prog = &text_scn.data;
 
     let mut packet1 = vec![
         0x01, 0x23, 0x45, 0x67, 0x89, 0xab,
@@ -111,7 +111,7 @@ fn main() {
         0x64, 0x66, 0x0au8
     ];
 
-    let mut vm = rbpf::EbpfVmFixedMbuff::new(&prog, 0x40, 0x50);
+    let mut vm = rbpf::EbpfVmFixedMbuff::new(prog, 0x40, 0x50);
     vm.register_helper(helpers::BPF_TRACE_PRINTK_IDX, helpers::bpf_trace_printf);
 
     let res = vm.prog_exec(&mut packet1);

+ 3 - 3
examples/to_json.rs

@@ -30,7 +30,7 @@ fn to_json(prog: &[u8]) -> String {
     // `LD_DW_IMM` instructions merged, and name and descriptions of the instructions.
     // If you prefer to use a lower-level representation, use `ebpf::to_insn_vec()` function
     // instead.
-    let insns = disassembler::to_insn_vec(&prog);
+    let insns = disassembler::to_insn_vec(prog);
     let mut json_insns = vec![];
     for insn in insns {
         json_insns.push(object!(
@@ -46,7 +46,7 @@ fn to_json(prog: &[u8]) -> String {
                 // number is negative. When values takes more than 32 bits with `lddw`, the cast
                 // has no effect and the complete value is printed anyway.
                 "imm"  => format!("{:#x}", insn.imm as i32), // => insn.imm,
-                "desc" => format!("{}",    insn.desc)
+                "desc" => insn.desc
             )
         );
     }
@@ -73,7 +73,7 @@ fn main() {
         None => panic!("Failed to look up .classifier section"),
     };
 
-    let ref prog = &text_scn.data;
+    let prog = &text_scn.data;
 
     println!("{}", to_json(&prog));
 }

+ 5 - 5
tests/misc.rs

@@ -108,7 +108,7 @@ fn test_vm_block_port() {
     //     None => panic!("Failed to look up .classifier section"),
     // };
     //
-    // let ref prog = &text_scn.data;
+    // let prog = &text_scn.data;
     // ---
 
     let prog = vec![
@@ -189,7 +189,7 @@ fn test_jit_block_port() {
     //     None => panic!("Failed to look up .classifier section"),
     // };
     //
-    // let ref prog = &text_scn.data;
+    // let prog = &text_scn.data;
     // ---
 
     let prog = vec![
@@ -263,11 +263,11 @@ fn test_vm_mbuff() {
         0x69, 0x10, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
     ];
-    let mut mem = vec![
+    let mem = vec![
         0xaa, 0xbb, 0x11, 0x22, 0xcc, 0xdd
     ];
 
-    let mut mbuff = vec![0u8; 32];
+    let mbuff = vec![0u8; 32];
     unsafe {
         let mut data     = mbuff.as_ptr().offset(8)  as *mut u64;
         let mut data_end = mbuff.as_ptr().offset(24) as *mut u64;
@@ -276,7 +276,7 @@ fn test_vm_mbuff() {
     }
 
     let vm = rbpf::EbpfVmMbuff::new(&prog);
-    assert_eq!(vm.prog_exec(&mut mem, &mut mbuff), 0x2211);
+    assert_eq!(vm.prog_exec(&mem, &mbuff), 0x2211);
 }
 
 // Program and memory come from uBPF test ldxh.