conflux-rust icon indicating copy to clipboard operation
conflux-rust copied to clipboard

`.get().unwrap()` on a HashMap.

Open ghost opened this issue 7 years ago • 2 comments

Code in Conflux: let index = self.node_index.get(&id).unwrap(); File Location: network/src/node_table.rs:783:29 Why is this bad: Using the Index trait ([]) is more clear and more concise. Remarks: if get() will produce NONE , which could be cause panic. try this: &self.node_index[&id]

ghost avatar May 06 '19 02:05 ghost

resolved

sparkmiw avatar May 14 '19 07:05 sparkmiw

We also have found the same kind of issue in following sections, as well;

Code in Conflux: self.indices_in_epochs.get(&epoch_index).unwrap(); File Location: core/src/consensus/mod.rs:188:13 Remarks: try this: &self.indices_in_epochs[&epoch_index]

Code in Conflux: let me_in_sync = *sync_graph | __________________________^ 349 | | .indices 350 | | .get(&self.arena[me_in_consensus].hash) 351 | | .unwrap(); File Location: core/src/consensus/mod.rs:348:26 Remarks: try this: 348 | let me_in_sync = sync_graph 349 | .indices[&self.arena[me_in_consensus].hash];

Code in Conflux: for index in self.indices_in_epochs.get(&pivot_index).unwrap() { File Location: core/src/consensus/mod.rs:583:26 Remarks: try this: &self.indices_in_epochs[&pivot_index]

Code in Conflux: *sync_inner.indices.get(&new_best_hash).unwrap(); File Location: core/src/consensus/mod.rs:622:13 Remarks: try this: sync_inner.indices[&new_best_hash]

Code in Conflux: Ok(self | ____________________^ 717 | | .indices_in_epochs 718 | | .get(&index) 719 | | .unwrap() File Location: core/src/consensus/mod.rs:716:20 Remarks: try this: try this | 716 | Ok(&self 717 | .indices_in_epochs[&index]

Code in Conflux: let parent_index = *inner.indices.get(parent_hash).unwrap(); File Location: core/src/consensus/mod.rs:935:28 Remarks: try this: inner.indices[parent_hash]

Code in Conflux: inner.indices_in_epochs.get(&epoch_index).unwrap(); File Location: core/src/consensus/mod.rs:1107:13 Remarks: try this: &inner.indices_in_epochs[&epoch_index]

Code in Conflux: let me: usize = inner.indices.get(block_hash).unwrap().clone(); File Location: core/src/consensus/mod.rs:1147:25 Remarks: try this: &inner.indices[block_hash]

Code in Conflux: let mut idx = inner.indices.get(block_hash).unwrap().clone(); File Location: core/src/consensus/mod.rs:1301:23 Remarks: try this: &inner.indices[block_hash]

Code in Conflux: let my_index_in_sync_graph = *sync_graph.indices.get(&my_hash).unwrap(); File Location: Core/src/consensus/mod.rs:1338:38 Remarks: try this: sync_graph.indices[&my_hash]

Code in Conflux: inner.indices_in_epochs.get(&pivot_index).unwrap().clone(); File Location: core/src/consensus/mod.rs:1542:17 Remarks: try this: &inner.indices_in_epochs[&pivot_index]

Code in Conflux: *inner.indices.get(block.block_header.parent_hash()).unwrap(); File Location: core/src/consensus/mod.rs:1593:13 Remarks: try this: inner.indices[block.block_header.parent_hash()]

Code in Conflux: *inner.indices.get(block.block_header.parent_hash()).unwrap(); File Location: core/src/consensus/mod.rs:1695:13 Remarks: try this: inner.indices[block.block_header.parent_hash()]

Code in Conflux: for index in inner | ______________________________^ 1979 | | .indices_in_epochs 1980 | | .get(&inner.pivot_chain[epoch_idx]) 1981 | | .unwrap() File Location: core/src/consensus/mod.rs:1978:30 Remarks: for index in &inner 1979 | .indices_in_epochs[&inner.pivot_chain[epoch_idx]]

Code in Conflux: let index = *self.indices.get(parent_hash).unwrap(); File Location: core/src/sync/synchronization_graph.rs:462:21 Remarks: try this: self.indices[parent_hash]

Code in Conflux: let me = *inner.indices.get(&hash).unwrap(); File Location: core/src/sync/synchronization_graph.rs:1031:18 Remarks: try this: inner.indices[&hash]

Code in Conflux: self.address_by_index.get(sender_index).unwrap().clone(); File Location: transactiongen/src/lib.rs:364:17 Remarks: try this: self.address_by_index[sender_index]

Code in Conflux: let sender_info = self.accounts.get(&sender_address).unwrap(); File Location: transactiongen/src/lib.rs:369:35 Remarks: try this: &self.accounts[&sender_address]

Code in Conflux: self.address_by_index.get(index).unwrap().clone() File Location: transactiongen/src/lib.rs:397:21 Remarks: try this: self.address_by_index[index]

Code in Conflux: self.address_by_index.get(sender_index).unwrap().clone(); File Location: transactiongen/src/lib.rs:454:17 Remarks: try this: self.address_by_index[sender_index]

Code in Conflux: let sender_info = self.accounts.get(&sender_address).unwrap(); File Location: transactiongen/src/lib.rs:460:35 Remarks: try this: &self.accounts[&sender_address]

Code in Conflux: self.address_by_index.get(receiver_index).unwrap().clone(); File Location: transactiongen/src/lib.rs:488:17 Remarks: try this: self.address_by_index[receiver_index]

ghost avatar May 21 '19 06:05 ghost