unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Petter Reinholdtsen <pere@hungry.com>
Cc: bug-gnu-emacs@gnu.org
Subject: Re: Strange error with cat (coreutils 4.5.2) on HP/UX
Date: 13 Oct 2002 00:36:00 +0200	[thread overview]
Message-ID: <2fl4rbrz3n3.fsf@saruman.uio.no> (raw)
In-Reply-To: <E180OtV-0006XX-00@saruman.uio.no>


[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 <stdio.h>
  #include <unistd.h>
  #include <sys/types.h>
  #include <sys/stat.h>
  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);

      reply	other threads:[~2002-10-12 22:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-12 16:13 Strange error with cat (coreutils 4.5.2) on HP/UX Petter Reinholdtsen
2002-10-12 22:36 ` Petter Reinholdtsen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2fl4rbrz3n3.fsf@saruman.uio.no \
    --to=pere@hungry.com \
    --cc=bug-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).