From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#40576: call-process-region does not accept nil as first argument Date: Sun, 12 Apr 2020 19:21:06 +0300 Message-ID: <83zhbgk74d.fsf@gnu.org> References: Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="99731"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 40576@debbugs.gnu.org, giorgian@gmail.com To: Philipp Stephani Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Apr 12 18:22:10 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jNfN4-000Pnp-DL for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 12 Apr 2020 18:22:10 +0200 Original-Received: from localhost ([::1]:34998 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jNfN3-0000ua-A1 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 12 Apr 2020 12:22:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43737) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jNfMw-0000uS-S0 for bug-gnu-emacs@gnu.org; Sun, 12 Apr 2020 12:22:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jNfMv-0000Dm-Q6 for bug-gnu-emacs@gnu.org; Sun, 12 Apr 2020 12:22:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:47163) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jNfMv-0000De-Mk for bug-gnu-emacs@gnu.org; Sun, 12 Apr 2020 12:22:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jNfMv-0004g3-Jq for bug-gnu-emacs@gnu.org; Sun, 12 Apr 2020 12:22:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 12 Apr 2020 16:22:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40576 X-GNU-PR-Package: emacs Original-Received: via spool by 40576-submit@debbugs.gnu.org id=B40576.158670848617936 (code B ref 40576); Sun, 12 Apr 2020 16:22:01 +0000 Original-Received: (at 40576) by debbugs.gnu.org; 12 Apr 2020 16:21:26 +0000 Original-Received: from localhost ([127.0.0.1]:58709 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jNfML-0004fE-TC for submit@debbugs.gnu.org; Sun, 12 Apr 2020 12:21:26 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:56827) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jNfMJ-0004ev-Oi for 40576@debbugs.gnu.org; Sun, 12 Apr 2020 12:21:24 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:60990) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1jNfME-0008FV-L0; Sun, 12 Apr 2020 12:21:18 -0400 Original-Received: from [176.228.60.248] (port=2125 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1jNfMD-0007te-M2; Sun, 12 Apr 2020 12:21:18 -0400 In-Reply-To: (message from Philipp Stephani on Sun, 12 Apr 2020 18:01:40 +0200) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:178257 Archived-At: > From: Philipp Stephani > Date: Sun, 12 Apr 2020 18:01:40 +0200 > Cc: 40576@debbugs.gnu.org > > > According to the documentation of call-process-region, > > If START is nil, that means to use the entire buffer contents; END is > > ignored. > > > > But when I run: > > (call-process-region nil nil "/bin/cat" t (current-buffer)) > > I get: > > Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil) > > call-process-region(nil nil "/bin/cat" t #) > > eval((call-process-region nil nil "/bin/cat" t (current-buffer)) nil) > > elisp--eval-last-sexp(t) > > eval-last-sexp(t) > > eval-print-last-sexp(nil) > > funcall-interactively(eval-print-last-sexp nil) > > call-interactively(eval-print-last-sexp nil nil) > > command-execute(eval-print-last-sexp) > > > > If, instead, I run: > > (call-process-region (point-min) (point-max) "/bin/cat" t (current-buffer)) > > > > It works. > > > > Am I interpreting the documentation wrong? > > Nope, looks like a genuine bug (that happens only if DELETE is non-nil). Right. But there's more here than meets the eye, because the change after which we started advertising the special meaning of nil for START exposed a problem: write_region, called from create_temp_file, has special meaning for START = nil: it widens the buffer and writes the entire buffer contents to the temp file. Which isn't right when write_region is called from call-process-region, as it allows access to inaccessible portion of the buffer, something we shouldn't do. So I propose the patch below to fix this bug on the master branch. Any objections? diff --git a/src/callproc.c b/src/callproc.c index 8883415..7f495a3 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -1039,8 +1039,8 @@ DEFUN ("call-process-region", Fcall_process_region, Scall_process_region, START and END are normally buffer positions specifying the part of the buffer to send to the process. -If START is nil, that means to use the entire buffer contents; END is -ignored. +If START is nil, that means to use the entire accessible part of the +buffer; END is ignored. If START is a string, then send that string to the process instead of any buffer contents; END is ignored. The remaining arguments are optional. @@ -1087,6 +1087,14 @@ t (mix it with ordinary output), or a file name string. empty_input = XFIXNUM (start) == XFIXNUM (end); } + if (NILP (start)) + { + XSETFASTINT (start, BEGV); + args[0] = start; + XSETFASTINT (end, ZV); + args[1] = end; + } + if (!empty_input) fd = create_temp_file (nargs, args, &infile); else