threads / patch / 7443

patchuse xmalloc in diff-delta.c and removed NULL verification in builtin-pack-objects.c from create_delta_index()

Subject: [PATCH] use xmalloc in diff-delta.c and removed NULL verification in builtin-pack-objects.c from create_delta_index()

## tl;dr

2 messages between Mar 28, 2007 and Mar 28, 2007. Diffs are folded; open one to read it.

replies: 1people: 1as markdown or json

Bruno Cesar Ribas· Mar 28, 2007, 01:04 UTC · lore
 builtin-pack-objects.c |    2 --
 diff-delta.c           |    8 ++------
 2 files changed, 2 insertions(+), 8 deletions(-)
Show changes to 2 files +2 −8

builtin-pack-objects.c, diff-delta.c

diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index b5f9648..04a4abc 100644
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
@@ -1254,8 +1254,6 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
        }
        if (!src->index) {
                src->index = create_delta_index(src->data, src_size);
-               if (!src->index)
-                       die("out of memory");
        }
 
        delta_buf = create_delta(src->index, trg->data, trg_size, &delta_size, max_size);
diff --git a/diff-delta.c b/diff-delta.c
index 9f998d0..011d7d6 100644
--- a/diff-delta.c
+++ b/diff-delta.c
@@ -157,9 +157,7 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize)
        memsize = sizeof(*index) +
                  sizeof(*hash) * hsize +
                  sizeof(*entry) * entries;
-       mem = malloc(memsize);
-       if (!mem)
-               return NULL;
+       mem = xmalloc(memsize);
        index = mem;
        mem = index + 1;
        hash = mem;
@@ -258,9 +256,7 @@ create_delta(const struct delta_index *index,
        outsize = 8192;
        if (max_size && outsize >= max_size)
                outsize = max_size + MAX_OP_SIZE + 1;
-       out = malloc(outsize);
-       if (!out)
-               return NULL;
+       out = xmalloc(outsize);
 
        /* store reference buffer size */
        i = index->src_size;
-- 
1.5.0.3

-- 
Bruno Ribas - ribas@c3sl.ufpr.br
http://web.inf.ufpr.br/ribas
C3SL: http://www.c3sl.ufpr.br 
Bruno Cesar Ribas· Mar 28, 2007, 03:03 UTC · re: Bruno Cesar Ribas · lore

Re: [PATCH] use xmalloc in diff-delta.c and removed NULL verification in builtin-pack-objects.c from create_delta_index()

please ignore. Sending in right way.
sorry.
On Tue, Mar 27, 2007 at 10:04:30PM -0300, Bruno Cesar Ribas wrote:
Show 54 quoted lines
>  builtin-pack-objects.c |    2 --
>  diff-delta.c           |    8 ++------
>  2 files changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
> index b5f9648..04a4abc 100644
> --- a/builtin-pack-objects.c
> +++ b/builtin-pack-objects.c
> @@ -1254,8 +1254,6 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
>         }
>         if (!src->index) {
>                 src->index = create_delta_index(src->data, src_size);
> -               if (!src->index)
> -                       die("out of memory");
>         }
>  
>         delta_buf = create_delta(src->index, trg->data, trg_size, &delta_size, max_size);
> diff --git a/diff-delta.c b/diff-delta.c
> index 9f998d0..011d7d6 100644
> --- a/diff-delta.c
> +++ b/diff-delta.c
> @@ -157,9 +157,7 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize)
>         memsize = sizeof(*index) +
>                   sizeof(*hash) * hsize +
>                   sizeof(*entry) * entries;
> -       mem = malloc(memsize);
> -       if (!mem)
> -               return NULL;
> +       mem = xmalloc(memsize);
>         index = mem;
>         mem = index + 1;
>         hash = mem;
> @@ -258,9 +256,7 @@ create_delta(const struct delta_index *index,
>         outsize = 8192;
>         if (max_size && outsize >= max_size)
>                 outsize = max_size + MAX_OP_SIZE + 1;
> -       out = malloc(outsize);
> -       if (!out)
> -               return NULL;
> +       out = xmalloc(outsize);
>  
>         /* store reference buffer size */
>         i = index->src_size;
> -- 
> 1.5.0.3
> 
> -- 
> Bruno Ribas - ribas@c3sl.ufpr.br
> http://web.inf.ufpr.br/ribas
> C3SL: http://www.c3sl.ufpr.br 
> -
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
-- 
Bruno Ribas - ribas@c3sl.ufpr.br
http://web.inf.ufpr.br/ribas
C3SL: http://www.c3sl.ufpr.br 

← back to recent threads