From 1fe218888aace1703f78e0af0059d7a15485bf7f Mon Sep 17 00:00:00 2001 From: Pádraig Brady
Date: Wed, 23 Jan 2013 12:34:46 +0000 Subject: head: with --bytes=-N only allocate memory as needed * src/head.c (elide_tail_bytes_pipe): Don't use calloc as that bypasses memory overcommit due to the zeroing requirement. Also realloc rather than malloc the pointer array to avoid dependence on overcommit entirely. * tests/misc/head-c.sh: Add a test case. Fixes http://bugs.gnu.org/13530 --- tests/misc/head-c.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/misc/head-c.sh b/tests/misc/head-c.sh index 6807c4d5a..eada8d550 100755 --- a/tests/misc/head-c.sh +++ b/tests/misc/head-c.sh @@ -1,5 +1,5 @@ #!/bin/sh -# exercise the fix of 2001-08-18, based on test case from Ian Bruce +# exercise head -c # Copyright (C) 2001-2013 Free Software Foundation, Inc. @@ -19,12 +19,17 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ head +# exercise the fix of 2001-08-18, based on test case from Ian Bruce echo abc > in || framework_failure_ - (head -c1; head -c1) < in > out || fail=1 case "$(cat out)" in ab) ;; *) fail=1 ;; esac +# Only allocate memory as needed. +# Coreutils <= 8.21 would allocate memory up front +# based on the value passed to -c +(ulimit -v 20000; head --bytes=-E < /dev/null) || fail=1 + Exit $fail -- cgit v1.2.3-70-g09d2