Commit b183ffe7 by Carlos Martín Nieto Committed by Vicent Marti

Make tree cache name a flex-array

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
parent b4171320
......@@ -14,12 +14,7 @@ static int read_tree_internal(git_tree_cache **out,
const char *name_start, *buffer;
int count;
int error = GIT_SUCCESS;
if ((tree = git__malloc(sizeof(git_tree_cache))) == NULL)
return GIT_ENOMEM;
memset(tree, 0x0, sizeof(git_tree_cache));
tree->parent = parent;
size_t name_len;
buffer = name_start = *buffer_in;
......@@ -28,18 +23,22 @@ static int read_tree_internal(git_tree_cache **out,
goto cleanup;
}
/* NUL-terminated tree name */
tree->name = git__strdup(name_start);
if (tree->name == NULL) {
error = GIT_ENOMEM;
goto cleanup;
}
if (++buffer >= buffer_end) {
error = GIT_EOBJCORRUPTED;
goto cleanup;
}
name_len = strlen(name_start);
if ((tree = git__malloc(sizeof(git_tree_cache) + name_len + 1)) == NULL)
return GIT_ENOMEM;
memset(tree, 0x0, sizeof(git_tree_cache));
tree->parent = parent;
/* NUL-terminated tree name */
memcpy(tree->name, name_start, name_len);
tree->name[name_len] = '\0';
/* Blank-terminated ASCII decimal number of entries in this tree */
if (git__strtol32(&count, buffer, &buffer, 10) < GIT_SUCCESS || count < -1) {
error = GIT_EOBJCORRUPTED;
......@@ -135,7 +134,6 @@ void git_tree_cache_free(git_tree_cache *tree)
for (i = 0; i < tree->children_count; ++i)
git_tree_cache_free(tree->children[i]);
free(tree->name);
free(tree->children);
free(tree);
}
......@@ -12,14 +12,13 @@
#include "git2/oid.h"
struct git_tree_cache {
char *name;
struct git_tree_cache *parent;
struct git_tree_cache **children;
size_t children_count;
ssize_t entries;
git_oid oid;
char name[GIT_FLEX_ARRAY];
};
typedef struct git_tree_cache git_tree_cache;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment