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/changelog.sh') diff --git a/lib/changelog.sh b/lib/changelog.sh index 7cb6c0b..3216f94 100644 --- a/lib/changelog.sh +++ b/lib/changelog.sh @@ -19,16 +19,12 @@ _ob_parse_changelog_error() { - local file= - local line_nr= - local msg_id= + local file="${1}" + local line_nr="${2}" + local msg_id="${3}" + shift 3 || _ob_abort local file_info= - file="${1}" - line_nr="${2}" - msg_id="${3}" - shift 3 - file_info="$(printf '%20s(l%d)' "${file}" "${line_nr}")" _ob_warn_msg "${msg_id}" "${file_info}" "${@}" @@ -57,15 +53,16 @@ _ob_get_changelog_expect_str() ## \fIchangelog\fP file or when \fIentry_cb\fP returns non-zero. ## @operand file req The file to parse, or "-" for standard input. ## @operand entry_cb req Callback to run for each entry. -## @return Returns 0 after parsing, or 125 on missing arguments. +## @return Returns 0 after parsing. ## @stderr Prints error messages on parse errors. ## @pure maybe This function has no side effects. Whether this function is ## subshell-safe in practice depends on whether \fIentry_cb\fP is ## subshell-safe. ob_parse_changelog() { - local file= - local entry_cb= + local file="${1}" + local entry_cb="${2}" + shift 2 || _ob_abort local line_nr= local line= local line_= @@ -78,13 +75,6 @@ ob_parse_changelog() local maintainer= local date= - if [ ${#} -eq 2 ]; then - file="${1}" - entry_cb="${2}" - else - return 125 - fi - # Parsing logic based on that of dpkg. line_nr=0 -- cgit v0.9.1