avoid asking ?alloc() for zero bytes.
Avoid asking for zero bytes when that change simplifies overall logic. Later we would change the wrapper to ask for 1 byte on platforms that return NULL for zero byte request. Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
6
diff.c
6
diff.c
@ -504,9 +504,9 @@ static void prepare_temp_file(const char *name,
|
|||||||
}
|
}
|
||||||
if (S_ISLNK(st.st_mode)) {
|
if (S_ISLNK(st.st_mode)) {
|
||||||
int ret;
|
int ret;
|
||||||
char *buf, buf_[1024];
|
char buf[PATH_MAX + 1]; /* ought to be SYMLINK_MAX */
|
||||||
buf = ((sizeof(buf_) < st.st_size) ?
|
if (sizeof(buf) <= st.st_size)
|
||||||
xmalloc(st.st_size) : buf_);
|
die("symlink too long: %s", name);
|
||||||
ret = readlink(name, buf, st.st_size);
|
ret = readlink(name, buf, st.st_size);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
die("readlink(%s)", name);
|
die("readlink(%s)", name);
|
||||||
|
@ -105,9 +105,13 @@ static int compare_pair_order(const void *a_, const void *b_)
|
|||||||
void diffcore_order(const char *orderfile)
|
void diffcore_order(const char *orderfile)
|
||||||
{
|
{
|
||||||
struct diff_queue_struct *q = &diff_queued_diff;
|
struct diff_queue_struct *q = &diff_queued_diff;
|
||||||
struct pair_order *o = xmalloc(sizeof(*o) * q->nr);
|
struct pair_order *o;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (!q->nr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
o = xmalloc(sizeof(*o) * q->nr);
|
||||||
prepare_order(orderfile);
|
prepare_order(orderfile);
|
||||||
for (i = 0; i < q->nr; i++) {
|
for (i = 0; i < q->nr; i++) {
|
||||||
o[i].pair = q->queue[i];
|
o[i].pair = q->queue[i];
|
||||||
|
@ -48,6 +48,9 @@ void diffcore_pathspec(const char **pathspec)
|
|||||||
for (i = 0; pathspec[i]; i++)
|
for (i = 0; pathspec[i]; i++)
|
||||||
;
|
;
|
||||||
speccnt = i;
|
speccnt = i;
|
||||||
|
if (!speccnt)
|
||||||
|
return;
|
||||||
|
|
||||||
spec = xmalloc(sizeof(*spec) * speccnt);
|
spec = xmalloc(sizeof(*spec) * speccnt);
|
||||||
for (i = 0; pathspec[i]; i++) {
|
for (i = 0; pathspec[i]; i++) {
|
||||||
spec[i].spec = pathspec[i];
|
spec[i].spec = pathspec[i];
|
||||||
|
22
index-pack.c
22
index-pack.c
@ -352,18 +352,24 @@ static int sha1_compare(const void *_a, const void *_b)
|
|||||||
static void write_index_file(const char *index_name, unsigned char *sha1)
|
static void write_index_file(const char *index_name, unsigned char *sha1)
|
||||||
{
|
{
|
||||||
struct sha1file *f;
|
struct sha1file *f;
|
||||||
struct object_entry **sorted_by_sha =
|
struct object_entry **sorted_by_sha, **list, **last;
|
||||||
xcalloc(nr_objects, sizeof(struct object_entry *));
|
|
||||||
struct object_entry **list = sorted_by_sha;
|
|
||||||
struct object_entry **last = sorted_by_sha + nr_objects;
|
|
||||||
unsigned int array[256];
|
unsigned int array[256];
|
||||||
int i;
|
int i;
|
||||||
SHA_CTX ctx;
|
SHA_CTX ctx;
|
||||||
|
|
||||||
for (i = 0; i < nr_objects; ++i)
|
if (nr_objects) {
|
||||||
sorted_by_sha[i] = &objects[i];
|
sorted_by_sha =
|
||||||
qsort(sorted_by_sha, nr_objects, sizeof(sorted_by_sha[0]),
|
xcalloc(nr_objects, sizeof(struct object_entry *));
|
||||||
sha1_compare);
|
list = sorted_by_sha;
|
||||||
|
last = sorted_by_sha + nr_objects;
|
||||||
|
for (i = 0; i < nr_objects; ++i)
|
||||||
|
sorted_by_sha[i] = &objects[i];
|
||||||
|
qsort(sorted_by_sha, nr_objects, sizeof(sorted_by_sha[0]),
|
||||||
|
sha1_compare);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
sorted_by_sha = list = last = NULL;
|
||||||
|
|
||||||
unlink(index_name);
|
unlink(index_name);
|
||||||
f = sha1create("%s", index_name);
|
f = sha1create("%s", index_name);
|
||||||
|
17
read-tree.c
17
read-tree.c
@ -294,17 +294,20 @@ static int unpack_trees(merge_fn_t fn)
|
|||||||
{
|
{
|
||||||
int indpos = 0;
|
int indpos = 0;
|
||||||
unsigned len = object_list_length(trees);
|
unsigned len = object_list_length(trees);
|
||||||
struct tree_entry_list **posns =
|
struct tree_entry_list **posns;
|
||||||
xmalloc(len * sizeof(struct tree_entry_list *));
|
|
||||||
int i;
|
int i;
|
||||||
struct object_list *posn = trees;
|
struct object_list *posn = trees;
|
||||||
merge_size = len;
|
merge_size = len;
|
||||||
for (i = 0; i < len; i++) {
|
|
||||||
posns[i] = ((struct tree *) posn->item)->entries;
|
if (len) {
|
||||||
posn = posn->next;
|
posns = xmalloc(len * sizeof(struct tree_entry_list *));
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
posns[i] = ((struct tree *) posn->item)->entries;
|
||||||
|
posn = posn->next;
|
||||||
|
}
|
||||||
|
if (unpack_trees_rec(posns, len, "", fn, &indpos))
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
if (unpack_trees_rec(posns, len, "", fn, &indpos))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (trivial_merges_only && nontrivial_merge)
|
if (trivial_merges_only && nontrivial_merge)
|
||||||
die("Merge requires file-level merging");
|
die("Merge requires file-level merging");
|
||||||
|
@ -263,6 +263,10 @@ void diff_tree_setup_paths(const char **p)
|
|||||||
|
|
||||||
paths = p;
|
paths = p;
|
||||||
nr_paths = count_paths(paths);
|
nr_paths = count_paths(paths);
|
||||||
|
if (nr_paths == 0) {
|
||||||
|
pathlens = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
pathlens = xmalloc(nr_paths * sizeof(int));
|
pathlens = xmalloc(nr_paths * sizeof(int));
|
||||||
for (i=0; i<nr_paths; i++)
|
for (i=0; i<nr_paths; i++)
|
||||||
pathlens[i] = strlen(paths[i]);
|
pathlens[i] = strlen(paths[i]);
|
||||||
|
Reference in New Issue
Block a user