From 9a1154cb9c038921d118f576c691c823ca32995d Mon Sep 17 00:00:00 2001 From: licunlong Date: Fri, 14 Jul 2023 15:46:21 +0800 Subject: [PATCH] fix: check if the words is empty before using it --- core/sysmaster/unit/rentry.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/sysmaster/unit/rentry.rs b/core/sysmaster/unit/rentry.rs index 312347e..5d7360c 100644 --- a/core/sysmaster/unit/rentry.rs +++ b/core/sysmaster/unit/rentry.rs @@ -30,6 +30,9 @@ use sysmaster::unit::{UnitRelations, UnitType}; pub(crate) fn unit_name_to_type(unit_name: &str) -> UnitType { let words: Vec<&str> = unit_name.split('.').collect(); + if words.is_empty() { + return UnitType::UnitTypeInvalid; + } UnitType::from_str(words[words.len() - 1]).unwrap_or(UnitType::UnitTypeInvalid) } -- 2.33.0