summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7d6fb37)
raw | patch | inline | side by side (parent: 7d6fb37)
author | Junio C Hamano <junkio@cox.net> | |
Mon, 26 Dec 2005 20:34:56 +0000 (12:34 -0800) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Tue, 27 Dec 2005 01:23:59 +0000 (17:23 -0800) |
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>
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>
diff.c | patch | blob | history | |
diffcore-order.c | patch | blob | history | |
diffcore-pathspec.c | patch | blob | history | |
index-pack.c | patch | blob | history | |
read-tree.c | patch | blob | history | |
tree-diff.c | patch | blob | history |
index c8159183dac830bf7cba20edf480712f039d7135..bfc864d9ccd94215aae9cc899c83e9ad149c590c 100644 (file)
--- a/diff.c
+++ b/diff.c
}
if (S_ISLNK(st.st_mode)) {
int ret;
- char *buf, buf_[1024];
- buf = ((sizeof(buf_) < st.st_size) ?
- xmalloc(st.st_size) : buf_);
+ char buf[PATH_MAX + 1]; /* ought to be SYMLINK_MAX */
+ if (sizeof(buf) <= st.st_size)
+ die("symlink too long: %s", name);
ret = readlink(name, buf, st.st_size);
if (ret < 0)
die("readlink(%s)", name);
diff --git a/diffcore-order.c b/diffcore-order.c
index b38122361f837e2e2577a89ae7aec311730b7f10..0bc2b22f848457a8e6ffafc6a1d9a26be677209f 100644 (file)
--- a/diffcore-order.c
+++ b/diffcore-order.c
void diffcore_order(const char *orderfile)
{
struct diff_queue_struct *q = &diff_queued_diff;
- struct pair_order *o = xmalloc(sizeof(*o) * q->nr);
+ struct pair_order *o;
int i;
+ if (!q->nr)
+ return;
+
+ o = xmalloc(sizeof(*o) * q->nr);
prepare_order(orderfile);
for (i = 0; i < q->nr; i++) {
o[i].pair = q->queue[i];
diff --git a/diffcore-pathspec.c b/diffcore-pathspec.c
index 68fe009132d1e900138a9d61bb7c658e23d9b76d..139fe882f9f85575af297a2131cfac2888ae3c73 100644 (file)
--- a/diffcore-pathspec.c
+++ b/diffcore-pathspec.c
for (i = 0; pathspec[i]; i++)
;
speccnt = i;
+ if (!speccnt)
+ return;
+
spec = xmalloc(sizeof(*spec) * speccnt);
for (i = 0; pathspec[i]; i++) {
spec[i].spec = pathspec[i];
diff --git a/index-pack.c b/index-pack.c
index d4ce3af5878e6e8d855783002f9d4e3f44af8d05..541d7bc1c1723c1a41cd35349b607223c94a4dca 100644 (file)
--- a/index-pack.c
+++ b/index-pack.c
static void write_index_file(const char *index_name, unsigned char *sha1)
{
struct sha1file *f;
- struct object_entry **sorted_by_sha =
- xcalloc(nr_objects, sizeof(struct object_entry *));
- struct object_entry **list = sorted_by_sha;
- struct object_entry **last = sorted_by_sha + nr_objects;
+ struct object_entry **sorted_by_sha, **list, **last;
unsigned int array[256];
int i;
SHA_CTX ctx;
- 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);
+ if (nr_objects) {
+ sorted_by_sha =
+ xcalloc(nr_objects, sizeof(struct object_entry *));
+ 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);
f = sha1create("%s", index_name);
diff --git a/read-tree.c b/read-tree.c
index e3b9c0d9fa1cb5a03d1a3a08f992074293285904..a46c6fe2f5d3234abe5dce0b7a9d44da07b6dae9 100644 (file)
--- a/read-tree.c
+++ b/read-tree.c
{
int indpos = 0;
unsigned len = object_list_length(trees);
- struct tree_entry_list **posns =
- xmalloc(len * sizeof(struct tree_entry_list *));
+ struct tree_entry_list **posns;
int i;
struct object_list *posn = trees;
merge_size = len;
- for (i = 0; i < len; i++) {
- posns[i] = ((struct tree *) posn->item)->entries;
- posn = posn->next;
+
+ if (len) {
+ 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)
die("Merge requires file-level merging");
diff --git a/tree-diff.c b/tree-diff.c
index 0ef06a9e36f55c0caec51064f552decd8a58be13..382092bce0be4ac82098ccc9c19d52df80f4eafd 100644 (file)
--- a/tree-diff.c
+++ b/tree-diff.c
paths = p;
nr_paths = count_paths(paths);
+ if (nr_paths == 0) {
+ pathlens = NULL;
+ return;
+ }
pathlens = xmalloc(nr_paths * sizeof(int));
for (i=0; i<nr_paths; i++)
pathlens[i] = strlen(paths[i]);