From c7801e1d7e787cd9a5b679a9fa65d31625143d29 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Fri, 6 Mar 2020 09:55:00 +0800 Subject: [PATCH] Fix off-by-one error message on indexing. --- src/result.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/result.rs b/src/result.rs index f7d6a8b9..ae05ee4b 100644 --- a/src/result.rs +++ b/src/result.rs @@ -134,9 +134,10 @@ impl std::fmt::Display for EvalAltResult { Self::ErrorArrayBounds(max, _, pos) if *max == 0 => write!(f, "{} ({})", desc, pos), Self::ErrorArrayBounds(max, index, pos) => write!( f, - "Array index {} is out of bounds: max {} elements ({})", + "Array index {} is out of bounds: only {} element{} in the array ({})", index, - max - 1, + max, + if *max > 1 { "s" } else { "" }, pos ), Self::ErrorStringBounds(_, index, pos) if *index < 0 => { @@ -145,9 +146,10 @@ impl std::fmt::Display for EvalAltResult { Self::ErrorStringBounds(max, _, pos) if *max == 0 => write!(f, "{} ({})", desc, pos), Self::ErrorStringBounds(max, index, pos) => write!( f, - "String index {} is out of bounds: max {} characters ({})", + "String index {} is out of bounds: only {} character{} in the string ({})", index, - max - 1, + max, + if *max > 1 { "s" } else { "" }, pos ), }