From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 5365 invoked from network); 23 Aug 2022 04:40:14 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 23 Aug 2022 04:40:14 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1661229614; b=NyESrbPV4mt9sptkMQa6WNd4ORFGzWlgs1DNXtz94i/MzLLRP16L81/1qwcmXAMS4XNgIAcLsC DGIfpCqewLhBqaQRMQYDSCGmYGV9H4C0zBAZ/vnp7ahui26wqHi7ZDbz5dSdxMdxZIJwLe37W3 eNM92ZyK1V4ryYJDRuuCcKUUtdv7NKWtnZm50pNCQASj34Wgr2fbSpjHU/NmBK8ebu7N1UAHgY JQTu7W7mooNjW6pHnugfQEG/ZxwaEJC7KN3Yzb9/5xzTbrHhfPEMvNtJsGeaqEXm+rxggF3geH ltwNMcmcwFdcw6KcQOIR335l0TJSZfnGEgdumf2ExUUVTw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-pf1-f173.google.com) smtp.remote-ip=209.85.210.173; dkim=pass header.d=awkwork-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=awkwork.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1661229614; bh=1jYBH88HVDSI2oEQbM9AV6+1iYO0cNoRr64xf1swsOQ=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=aUoWtHl9hZHqXB/RAahyXpig4dksHbn9w9GdRU/cd98NO8z+Cl0eZpgqCRy5Km2fK8gu4eOUsS /dkHOQ+rfiojN7tFGk5Pqw1Hh1JEOosgqLAWbbDqhrjQmik0k/CElLi0EcnvVi7NeQqvOC3Zrl IB8315ezgE9ndToVaWYci4mWXho7tHpvPzhgWQKcVkopiu+2rJSdxjmvTqhmcyrhkvjkFJms6n m1X5DDt5F7YhXNKS21YKUhttzeJUgofSZrMuE779cTd+JDbwfeW3BiK4qHH/ermqsVn0pEJORk z/Ma0dFEs/+1mFJ0DRv8TzF1vjSRZBtwx/tY+6sXPZeN5w==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=xmy32NT4m+IZqCuP/LY718nRUli1cLhNngO+T3GEgFM=; b=IVuCSdk1qPZKXfSBMKvcWzGsmS Yrm/lJ9kvE2EWaU8YBJ6tZLnJE76FS2CQEESrbmTh8X8YgyNcyZSu9Sn0rQ9H6srOSW+mnbxoTfHu S+T1oORcMkEvj2eI/TQ6InHCinbdsqhiModE8BY5NzXc6FVMK/o3Q8Z35O1pRD6q9XMReMK4ycAzK ctrOGIQxrGnj3c6Af8h6MU5fQBeNvw1Cpl0NldwYRcqnjxnhTH7KBS07Ot3K6ozUPRrRtsykGznHH +19rwL6RzPWO5pQzoLSUvcOraJCFaFDrr4Mkna85jk6LiBykTi9HcIQTVvucgfc1Xnqvs5bPq1Dk4 +9vnvddg==; Received: from authenticated user by zero.zsh.org with local id 1oQLi1-0001FO-IY; Tue, 23 Aug 2022 04:40:13 +0000 Authentication-Results: zsh.org; iprev=pass (mail-pf1-f173.google.com) smtp.remote-ip=209.85.210.173; dkim=pass header.d=awkwork-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=awkwork.com; arc=none Received: from mail-pf1-f173.google.com ([209.85.210.173]:37812) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1oQLho-0000t8-9l; Tue, 23 Aug 2022 04:40:01 +0000 Received: by mail-pf1-f173.google.com with SMTP id x15so11465163pfp.4 for ; Mon, 22 Aug 2022 21:40:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=awkwork-com.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=xmy32NT4m+IZqCuP/LY718nRUli1cLhNngO+T3GEgFM=; b=hf0U/EUNu4QSW9b5ljnhG7dLmOlOUMjT1RMX1foW+o/NoqTfdD3lfOVMxcf3ozaL3u vCxC9Hom+cPawDjwAQeYyIlozSZDT/zGsHvImCd96U9F62EIcOHsD2cipUT91oGYUU6F XRxXOigEVoURx0hSuswHOyntYuHvVZSqD7ZCYlJozqzkQFt55s/1kW9DaC0r5mU5yFF7 bAy//pjFKJ83qeLZbS5BPNWMLU7lk1a5z0zvezrxqL0vjY/Q7YoU5GpGoDvc8Ew/+lFP 1vqZuRPK9LA8Y7wseBVqvT6FIaHY2vHcK6/68fFxL5j1rfjgokhKjt9njNElwizvlJZF gONQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=xmy32NT4m+IZqCuP/LY718nRUli1cLhNngO+T3GEgFM=; b=E7KSP26q7cZhX7RbUcciVSXlNkqN/yhVrwiLUbm9ehD1tHbefqT6I3x7ZJFXTc+H2U tLGLEH2tDM7GFAHOqQoEEPMnHhYLFQviI9ClM5ip2NqyTP5yxj7wE1ZSi2ouo7GUFIgC cxohhIxgZTFrzwmgpaFNXGcQ+IFzx7wKX9W/c6O9Bdan41L1nOiyjN8jmemvRPzX3UU4 WG1qEe5MN5DnYI6LALfv5xxOdSN+BEtSmSKf+a7EelPk5YWScMqEjlKZzpGwcou3PnK3 mTecnyUEHyy/GcCmyvvI2jzYfkdaMZf2+11syxjt9l6Fh5mnqPmjtm5gvPYs/hHw8zFd 3cVQ== X-Gm-Message-State: ACgBeo1jYxkp8kDdu7LplwJiryKWfbmDdQlXBTqvfYlh1pYDbT3xFmmY vcuFqfEw+jQl6Mp6F+utxTf+rdfX5Gotlo8kYvTKTxpWFsI= X-Google-Smtp-Source: AA6agR7yGxMzxEc22TWJl075lvw041+f4APeMNb0IymLD0q5kl9Vji+njh9UQiwdJ8XwqDSiiI2aoMAMPznzAXdzOPI= X-Received: by 2002:aa7:90d1:0:b0:536:70e1:5e83 with SMTP id k17-20020aa790d1000000b0053670e15e83mr11239157pfk.11.1661229598946; Mon, 22 Aug 2022 21:39:58 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Alan Wagner-Krankel Date: Mon, 22 Aug 2022 23:39:32 -0500 Message-ID: Subject: Re: zargs error with some combinations of arguments To: Bart Schaefer Cc: zsh-workers@zsh.org Content-Type: text/plain; charset="UTF-8" X-Seq: 50497 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: I think we're both proposing basically the same change. It looks like the format of my context diff hid the use of the calculated 'a' value later in the code. Here's the diff listing from git: diff --git a/Functions/Misc/zargs b/Functions/Misc/zargs index 782d681..c7e96b8 100644 --- a/Functions/Misc/zargs +++ b/Functions/Misc/zargs @@ -194,7 +194,7 @@ else return 1 fi -local -i end c=0 +local -i end a c=0 if [[ $eof == -(e|-eof) ]]; then ((end=ARGC+1)) elif (( $#eof )); then end=$argv[(i)${eof##-(e|-eof=)}] else end=$argv[(i)--] @@ -265,6 +265,13 @@ then return 1 fi +(( a = s - ${#:-"$command "} )) +if (( a <= 0 )) +then + print -u2 'zargs: value for max-chars must be >= command length' + return 1 +fi + l=${${${l##*-(l|L|-max-lines(=|))}[-1]}:-${${l[1]:+1}:-$ARGC}} if (( l <= 0 )) then @@ -305,7 +312,7 @@ do repeat $P do ((ARGC)) || break - for (( end=l; end && ${(c)#argv[1,end]} > s; end/=2 )) { } + for (( end=l; end && ${(c)#argv[1,end]} > a; end/=2 )) { } (( end > n && ( end = n ) )) args=( "${(@)argv[1,end]}" ) shift $((end > ARGC ? ARGC : end)) In this line: (( a = s - ${#:-"$command "} )) 's' is the max size of the total command line. The calculated value 'a' represents the maximum number of characters that can be used for arguments to the command. It's stored in a variable to avoid recalculating it each time in the primary nested loop. The 'command' variable is an array, and we also need a space for the separator between the command and the parameters. ${#:-"$command "} was my (possibly too cute) way of calculating the total length of the command plus the space. This should give the same result: (( a = s - ${(c)#command} - 1 )) The error message after the 'a <= 0' test is only going to occur with some edge cases and nonsensical parameters, e.g.: zargs -s 10 -- a b c -- somelongcmd It's not really needed. If the command is too large, the 'cannot fit single argument within size limit' error message will do the job. Thanks for looking into this, Awk