all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Emanuele Giaquinta <emanuele.giaquinta@gmail.com>
To: Chong Yidong <cyd@stupidchicken.com>
Cc: emacs-devel@gnu.org
Subject: Re: [Emacs-diffs] emacs/src term.c
Date: Mon, 8 Dec 2008 19:23:37 +0100	[thread overview]
Message-ID: <20081208182337.GC4177@orion.lan> (raw)
In-Reply-To: <E1L9hLb-000768-Bm@cvs.savannah.gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1346 bytes --]

On Mon, Dec 08, 2008 at 02:44:31PM +0000, Chong Yidong wrote:

> Index: term.c
> ===================================================================
> RCS file: /sources/emacs/emacs/src/term.c,v
> retrieving revision 1.229
> retrieving revision 1.230
> diff -u -b -r1.229 -r1.230
> --- term.c	27 Sep 2008 10:50:48 -0000	1.229
> +++ term.c	8 Dec 2008 14:44:30 -0000	1.230
> @@ -581,10 +581,10 @@
>    required = MAX_MULTIBYTE_LENGTH * src_len;
>    if (encode_terminal_src_size < required)
>      {
> -      if (encode_terminal_src_size == 0)
> -	encode_terminal_src = xmalloc (required);
> -      else
> +      if (encode_terminal_src)
>  	encode_terminal_src = xrealloc (encode_terminal_src, required);
> +      else
> +	encode_terminal_src = xmalloc (required);
>        encode_terminal_src_size = required;
>      }
>  
> @@ -740,6 +740,10 @@
>    if (encode_terminal_dst_size == 0)
>      {
>        encode_terminal_dst_size = encode_terminal_src_size;
> +      if (encode_terminal_dst)
> +	encode_terminal_dst = xrealloc (encode_terminal_dst,
> +					encode_terminal_dst_size);
> +      else
>        encode_terminal_dst = xmalloc (encode_terminal_dst_size);
>      }
>    coding->destination = encode_terminal_dst;

Any reason to not simply use realloc? (realloc(NULL, size) == malloc(size))
A patch is attached in case it is ok.

Emanuele

[-- Attachment #2: realloc.diff --]
[-- Type: text/x-diff, Size: 1645 bytes --]

diff --git a/src/term.c b/src/term.c
index 32bc4f6..dc0cb38 100644
--- a/src/term.c
+++ b/src/term.c
@@ -581,10 +581,7 @@ encode_terminal_code (src, src_len, coding)
   required = MAX_MULTIBYTE_LENGTH * src_len;
   if (encode_terminal_src_size < required)
     {
-      if (encode_terminal_src)
 	encode_terminal_src = xrealloc (encode_terminal_src, required);
-      else
-	encode_terminal_src = xmalloc (required);
       encode_terminal_src_size = required;
     }
 
@@ -740,11 +737,8 @@ encode_terminal_code (src, src_len, coding)
   if (encode_terminal_dst_size == 0)
     {
       encode_terminal_dst_size = encode_terminal_src_size;
-      if (encode_terminal_dst)
 	encode_terminal_dst = xrealloc (encode_terminal_dst,
 					encode_terminal_dst_size);
-      else
-	encode_terminal_dst = xmalloc (encode_terminal_dst_size);
     }
   coding->destination = encode_terminal_dst;
   coding->dst_bytes = encode_terminal_dst_size;
@@ -1218,15 +1212,10 @@ calculate_costs (struct frame *frame)
       max_frame_lines = max (max_frame_lines, FRAME_LINES (frame));
       max_frame_cols = max (max_frame_cols, FRAME_COLS (frame));
 
-      if (char_ins_del_vector != 0)
         char_ins_del_vector
           = (int *) xrealloc (char_ins_del_vector,
                               (sizeof (int)
                                + 2 * max_frame_cols * sizeof (int)));
-      else
-        char_ins_del_vector
-          = (int *) xmalloc (sizeof (int)
-                             + 2 * max_frame_cols * sizeof (int));
 
       bzero (char_ins_del_vector, (sizeof (int)
                                    + 2 * max_frame_cols * sizeof (int)));

           reply	other threads:[~2008-12-08 18:23 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <E1L9hLb-000768-Bm@cvs.savannah.gnu.org>]

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

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

  git send-email \
    --in-reply-to=20081208182337.GC4177@orion.lan \
    --to=emanuele.giaquinta@gmail.com \
    --cc=cyd@stupidchicken.com \
    --cc=emacs-devel@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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.