From 9033d4b6b9b85ab3e502b376daf66ae566c026b6 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Wed, 13 Mar 2019 02:51:56 -0400 Subject: libopkbuild: Abort on invalid function arguments Shift arguments and abort instead of returning 125. Incorrect numbers of function arguments suggest application/library incompatibilities or serious errors by the application developer. Either way, the application developer should be made immediately aware of this (and not allowed to simply not check return values), and continuing to run and handle any further API calls may be unsafe. --- (limited to 'lib/deps.sh') diff --git a/lib/deps.sh b/lib/deps.sh index 64553aa..348839a 100644 --- a/lib/deps.sh +++ b/lib/deps.sh @@ -79,37 +79,37 @@ ob_parse_dep() p) pkg_var="${OPTARG}" if ! _ob_validate_var_name "${pkg_var}"; then - return 125 + _ob_abort fi ;; q) archqual_var="${OPTARG}" if ! _ob_validate_var_name "${archqual_var}"; then - return 125 + _ob_abort fi ;; r) rel_var="${OPTARG}" if ! _ob_validate_var_name "${rel_var}"; then - return 125 + _ob_abort fi ;; v) ver_var="${OPTARG}" if ! _ob_validate_var_name "${ver_var}"; then - return 125 + _ob_abort fi ;; A) arches_var="${OPTARG}" if ! _ob_validate_var_name "${arches_var}"; then - return 125 + _ob_abort fi ;; l) plats_var="${OPTARG}" if ! _ob_validate_var_name "${plats_var}"; then - return 125 + _ob_abort fi ;; a) @@ -119,17 +119,14 @@ ob_parse_dep() host_plat="${OPTARG}" ;; ?) - return 125 + _ob_abort ;; esac done shift $(($OPTIND - 1)) - if [ ${#} -eq 1 ]; then - dep="${1}" - else - return 125 - fi + dep="${1}" + shift 1 || _ob_abort # pkg[:archqual] [(rel ver)] [\[arches\]] [] dep_re='s/^ *([^ \(\[<]+) *(\((<<|<=|=|>=|>>) *(.+)\))?' @@ -200,7 +197,7 @@ ob_parse_dep() ## Required. ## @option -u - Treat \fIdeps\fP as a union list. ## @operand deps req The list of dependencies to reduce. -## @return Returns 0 on success or 125 on invalid option or missing \fIdeps\fP. +## @return Returns 0 on success. ## @stdout Prints the reduced list of dependencies. ## @pure yes This function has no side effects. ob_reduce_deps() @@ -230,17 +227,14 @@ ob_reduce_deps() union='true' ;; ?) - return 125 + _ob_abort ;; esac done shift $(($OPTIND - 1)) - if [ ${#} -eq 1 ]; then - deps="${1}" - else - return 125 - fi + local deps="${1}" + shift 1 || _ob_abort IFS=',' for dep_and in ${deps}; do -- cgit v0.9.1