mirror of
https://github.com/hinto-janai/gupax.git
synced 2024-11-17 01:37:52 +00:00
main: fix potential index panic
This commit is contained in:
parent
a4eba8a77f
commit
29ca04c4f1
2 changed files with 17 additions and 3 deletions
|
@ -349,6 +349,10 @@ impl Node {
|
|||
vec![("Local Monero Node".to_string(), Self::localhost())]
|
||||
}
|
||||
|
||||
pub fn new_tuple() -> (String, Self) {
|
||||
("Local Monero Node".to_string(), Self::localhost())
|
||||
}
|
||||
|
||||
// Convert [String] to [Node] Vec
|
||||
pub fn from_str_to_vec(string: &str) -> Result<Vec<(String, Self)>, TomlError> {
|
||||
let nodes: toml::map::Map<String, toml::Value> = match toml::de::from_str(string) {
|
||||
|
@ -483,6 +487,10 @@ impl Pool {
|
|||
vec![("Local P2Pool".to_string(), Self::p2pool())]
|
||||
}
|
||||
|
||||
pub fn new_tuple() -> (String, Self) {
|
||||
("Local P2Pool".to_string(), Self::p2pool())
|
||||
}
|
||||
|
||||
pub fn from_str_to_vec(string: &str) -> Result<Vec<(String, Self)>, TomlError> {
|
||||
let pools: toml::map::Map<String, toml::Value> = match toml::de::from_str(string) {
|
||||
Ok(map) => {
|
||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -421,8 +421,11 @@ impl App {
|
|||
// Handle [node_vec] overflow
|
||||
info!("App Init | Handling [node_vec] overflow");
|
||||
if og.p2pool.selected_index > app.og_node_vec.len() {
|
||||
warn!("App | Overflowing manual node index [{} > {}], resetting to 1", og.p2pool.selected_index, app.og_node_vec.len());
|
||||
let (name, node) = app.og_node_vec[0].clone();
|
||||
warn!("App | Overflowing manual node index [{} > {}]", og.p2pool.selected_index, app.og_node_vec.len());
|
||||
let (name, node) = match app.og_node_vec.get(0) {
|
||||
Some(zero) => zero.clone(),
|
||||
None => Node::new_tuple(),
|
||||
};
|
||||
og.p2pool.selected_index = 0;
|
||||
og.p2pool.selected_name = name.clone();
|
||||
og.p2pool.selected_ip = node.ip.clone();
|
||||
|
@ -438,7 +441,10 @@ impl App {
|
|||
info!("App Init | Handling [pool_vec] overflow...");
|
||||
if og.xmrig.selected_index > app.og_pool_vec.len() {
|
||||
warn!("App | Overflowing manual pool index [{} > {}], resetting to 1", og.xmrig.selected_index, app.og_pool_vec.len());
|
||||
let (name, pool) = app.og_pool_vec[0].clone();
|
||||
let (name, pool) = match app.og_pool_vec.get(0) {
|
||||
Some(zero) => zero.clone(),
|
||||
None => Pool::new_tuple(),
|
||||
};
|
||||
og.xmrig.selected_index = 0;
|
||||
og.xmrig.selected_name = name.clone();
|
||||
og.xmrig.selected_ip = pool.ip.clone();
|
||||
|
|
Loading…
Reference in a new issue