bug-coreutils
[Top][All Lists]
Advanced

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

[PATCH] pr: avoid two over-allocations


From: Jim Meyering
Subject: [PATCH] pr: avoid two over-allocations
Date: Mon, 18 Jan 2010 07:59:29 +0100

Each of these variables is declared as an "int *".

>From bbf85cc44fc18ec8f085edf1dcf73fc1247648a0 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Mon, 18 Jan 2010 07:53:44 +0100
Subject: [PATCH] pr: avoid two over-allocations

* src/pr.c (init_store_cols): Allocate N*sizeof(*VAR) bytes,
not N*sizeof(int*).  The latter would mistakenly allocate double
the required space on a system with 8-byte pointers.
---
 src/pr.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/pr.c b/src/pr.c
index 1b08894..10770cb 100644
--- a/src/pr.c
+++ b/src/pr.c
@@ -1915,10 +1915,10 @@ init_store_cols (void)

   free (line_vector);
   /* FIXME: here's where it was allocated.  */
-  line_vector = xmalloc ((total_lines + 1) * sizeof (int *));
+  line_vector = xmalloc ((total_lines + 1) * sizeof *line_vector);

   free (end_vector);
-  end_vector = xmalloc (total_lines * sizeof (int *));
+  end_vector = xmalloc (total_lines * sizeof *end_vector);

   free (buff);
   buff_allocated = (use_col_separator
--
1.6.6.638.g2bc54




reply via email to

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