Skip to content

Commit 048f276

Browse files
dmpotspearce
authored andcommitted
do not segfault if make_cache_entry failed
Signed-off-by: Dmitry Potapov <[email protected]> Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent 52e8370 commit 048f276

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

builtin-apply.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,6 +2586,8 @@ static void build_fake_ancestor(struct patch *list, const char *filename)
25862586
sha1_ptr = sha1;
25872587

25882588
ce = make_cache_entry(patch->old_mode, sha1_ptr, name, 0, 0);
2589+
if (!ce)
2590+
die("make_cache_entry failed for path '%s'", name);
25892591
if (add_index_entry(&result, ce, ADD_CACHE_OK_TO_ADD))
25902592
die ("Could not add %s to temporary index", name);
25912593
}

builtin-checkout.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ static int checkout_merged(int pos, struct checkout *state)
206206
ce = make_cache_entry(create_ce_mode(active_cache[pos+1]->ce_mode),
207207
sha1,
208208
path, 2, 0);
209+
if (!ce)
210+
die("make_cache_entry failed for path '%s'", path);
209211
status = checkout_entry(ce, state, NULL);
210212
return status;
211213
}

builtin-reset.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ static void update_index_from_diff(struct diff_queue_struct *q,
121121
struct cache_entry *ce;
122122
ce = make_cache_entry(one->mode, one->sha1, one->path,
123123
0, 0);
124+
if (!ce)
125+
die("make_cache_entry failed for path '%s'",
126+
one->path);
124127
add_cache_entry(ce, ADD_CACHE_OK_TO_ADD |
125128
ADD_CACHE_OK_TO_REPLACE);
126129
} else

0 commit comments

Comments
 (0)