[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#6417: [Bug 591969] Re: dd bs=3G || ubuntu-bug coreutils

From: Paul Eggert
Subject: bug#6417: [Bug 591969] Re: dd bs=3G || ubuntu-bug coreutils
Date: Mon, 12 Jul 2010 17:22:17 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20100527 Thunderbird/3.0.5

On 06/14/10 13:35, Jim Meyering wrote:
> Paul Eggert wrote:
>> Or, we could output both, as in "3EiB (3458764513820540928 bytes)",
>> where the first is the string and the second is the integer that
>> we converted it to.
> That would be an improvement, indeed.
> ...
> You're welcome to patch further.

Thanks, I tried it out, and discovered that outputting the exact
number isn't right, since the user might complain "I asked for 1 MB;
why is it complaining about 1005000 bytes"?  Since the slop is small,
it's better to simply output the user-requested size and omit the
overhead, which is plausibly small enough to be like malloc's internal
overhead anyway.  Also, from a technical-wording point of view it's
more accurate that way, since the message talks about the buffer size,
not the malloc request size.

Anyway, I installed this; of course further improvements are welcome.

>From 335b59b9625758f92ba82cd6b7138f7423df60ef Mon Sep 17 00:00:00 2001
From: Paul R. Eggert <address@hidden>
Date: Mon, 12 Jul 2010 17:12:43 -0700
Subject: [PATCH] dd: also spell out size on memory exhaustion

* src/dd.c (dd_copy): Use requested blocksize (not adjusted) in
diagnostic, to forestall user complaints that the numbers don't
match exactly.  Report both exact and human-readable sizes, using
a message format that is consistent with both "BBBB bytes (N XB)
copied" in dd.c and "memory exhausted" in lib/xmalloc.c.
 src/dd.c |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/src/dd.c b/src/dd.c
index c9b8cbd..ab8b84c 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -1603,12 +1603,11 @@ dd_copy (void)
      It is necessary when accessing raw (i.e. character special) disk
      devices on Unixware or other SVR4-derived system.  */
-  size_t sz = input_blocksize + INPUT_BLOCK_SLOP;
-  real_buf = malloc (sz);
+  real_buf = malloc (input_blocksize + INPUT_BLOCK_SLOP);
   if (!real_buf)
     error (EXIT_FAILURE, 0,
-           _("failed to allocate an input buffer of size %s"),
-           human_size (sz));
+           _("memory exhausted by input buffer of size %zu bytes (%s)"),
+           input_blocksize, human_size (input_blocksize));
   ibuf = real_buf;
   ibuf += SWAB_ALIGN_OFFSET;   /* allow space for swab */
@@ -1618,12 +1617,11 @@ dd_copy (void)
   if (conversions_mask & C_TWOBUFS)
       /* Page-align the output buffer, too.  */
-      sz = output_blocksize + OUTPUT_BLOCK_SLOP;
-      real_obuf = malloc (sz);
+      real_obuf = malloc (output_blocksize + OUTPUT_BLOCK_SLOP);
       if (!real_obuf)
         error (EXIT_FAILURE, 0,
-               _("failed to allocate an output buffer of size %s"),
-               human_size (sz));
+               _("memory exhausted by output buffer of size %zu bytes (%s)"),
+               output_blocksize, human_size (output_blocksize));
       obuf = ptr_align (real_obuf, page_size);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]