changeset 580:ac7ab3d98cd2

farray.sh: more thorough index checks where needed. Numeric evaluation is sometimes sloppy and seems to return 0 on errors in many cases.
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 15 Sep 2024 23:09:57 +0200
parents 4fd6be157c70
children fac8ca743e40
files share/local-bsdtools/farray.sh
diffstat 1 files changed, 3 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/share/local-bsdtools/farray.sh	Sun Sep 15 22:35:37 2024 +0200
+++ b/share/local-bsdtools/farray.sh	Sun Sep 15 23:09:57 2024 +0200
@@ -390,6 +390,7 @@
     [ -z "${__farr_index}" ] && _farr_fatal "no valid index for set given"
     # make it to a number
     __farr_index=$((__farr_index + 0))
+    [ ${__farr_index} -lt 1 ] && _farr_fatal "index must be >= 1"
     __farr_value="${3-}"
 
     # For proper quoting: see farray_append
@@ -644,7 +645,9 @@
     __farr_searched_value="$2"
 
     __farr_start=$((${4-1} + 0))
+    [ ${__farr_start} -lt 1 ] && _farr_fatal "start index must be >= 1"
     __farr_end=$((${5-${__farr_len}} + 0))
+    [ ${__farr_end} -lt 1 ] && _farr_fatal "end index must be >= 1"
 
     __farr_cur_idx=${__farr_start}
     while [ ${__farr_cur_idx} -le ${__farr_end} ]; do