From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Petter Reinholdtsen Newsgroups: gmane.emacs.bugs Subject: Re: Strange error with cat (coreutils 4.5.2) on HP/UX Date: 13 Oct 2002 00:36:00 +0200 Sender: bug-gnu-emacs-admin@gnu.org Message-ID: <2fl4rbrz3n3.fsf@saruman.uio.no> References: NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1034462224 22158 127.0.0.1 (12 Oct 2002 22:37:04 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sat, 12 Oct 2002 22:37:04 +0000 (UTC) Cc: bug-gnu-emacs@gnu.org Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 180UsY-0005lD-00 for ; Sun, 13 Oct 2002 00:37:02 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 180Usj-0003js-00; Sat, 12 Oct 2002 18:37:13 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 180Urf-0001lR-00 for bug-gnu-emacs@gnu.org; Sat, 12 Oct 2002 18:36:07 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 180Urd-0001hg-00 for bug-gnu-emacs@gnu.org; Sat, 12 Oct 2002 18:36:07 -0400 Original-Received: from pat.uio.no ([129.240.130.16]) by monty-python.gnu.org with esmtp (Exim 4.10) id 180Urc-0001do-00 for bug-gnu-emacs@gnu.org; Sat, 12 Oct 2002 18:36:05 -0400 Original-Received: from saruman.uio.no ([129.240.201.202]) by pat.uio.no with esmtp (Exim 2.12 #7) id 180UrZ-0007If-00; Sun, 13 Oct 2002 00:36:01 +0200 Original-Received: from pre by saruman.uio.no with local (Exim 2.12 #7) id 180UrY-0005Fu-00; Sun, 13 Oct 2002 00:36:01 +0200 Original-To: Petter Reinholdtsen X-Message-Flag: Message text blocked: ADULT LANGUAGE/SITUATIONS Reply-By: Tue, 1 Jan 1801 04:37:40 +1000 In-Reply-To: Original-Lines: 55 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.2 Errors-To: bug-gnu-emacs-admin@gnu.org X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Bug reports for GNU Emacs, the Swiss army knife of text editors List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.bugs:3691 X-Report-Spam: http://spam.gmane.org/gmane.emacs.bugs:3691 [Petter Reinholdtsen] > I get the message 'cat: memory exhausted' when trying to run 'cat' on > a big file across rsh to a HP/UX box. The problem goes away when I > try to do this in an interactive shell, or if I pipe the output from > cat through dd: I've tracked it down to a problem with fstat()/st_blksize when stdout is sent through rsh. I used this code to test: #include #include #include #include int main(int argc, char *argv[]) { struct stat stat_buf; fstat(STDOUT_FILENO, &stat_buf); printf("st_blksize=%d(0x%x) high=%d low=%d\n", stat_buf.st_blksize, stat_buf.st_blksize >> 16, stat_buf.st_blksize & 0xffff); return 0; } When I run it using an interactive shell on the HP/UX box: st_blksize=65536(0x10000) high=1 low=0 If I run it using 'rsh host testprog', the output is worse: st_blksize=2147421096(0x7fff0ba8) high=32767 low=2984 If I instead use dd in front (rsh snipe "/tmp/foo |dd"), I get this: st_blksize=8192(0x2000) high=0 low=8192'. Perhaps the code in cat.c should check for insanely large values, and not try to call xmalloc() with any large number? Here is a stupid patch to fix the problem. I'm not sure if this is the right fix, but at least GNU cat works again on HP/UX. diff -ur src-4.5.2/src/cat.c src-4.5.2-local/src/cat.c --- src-4.5.2/src/cat.c 2002-09-29 23:25:03.000000000 +0200 +++ src-4.5.2-local/src/cat.c 2002-10-13 00:32:51.000000000 +0200 @@ -804,6 +804,10 @@ --version, or --help) were specified, use `cat', otherwise use `simple_cat'. */ + /* Special case for HP/UX 11.00 */ + if (outsize > 0x20000) /* Avoid xmalloc() on very huge numbers */ + outsize = DEV_BSIZE; + if (options == 0) { insize = max (insize, outsize);