summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-11-13 15:36:45 -0500
committerEdward Thomson <ethomson@edwardthomson.com>2015-11-16 22:58:59 -0500
commitde999f260ffdf0266bc0109cd71621ecf65cad98 (patch)
treeddaa52c4b6aed1ef457b405e64bff23825cb77d3
parentd1101263f751a33d70ec585da908bec938f587fd (diff)
downloadlibgit2-de999f260ffdf0266bc0109cd71621ecf65cad98.tar.gz
checkout::crlf test: don't crash when no idx entry
When there's no matching index entry (for whatever reason), don't try to dereference the null return value to get at the id. Otherwise when we break something in the index API, the checkout test crashes for confusing reasons and causes us to step through it in a debugger thinking that we had broken much more than we actually did.
-rw-r--r--tests/checkout/crlf.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/tests/checkout/crlf.c b/tests/checkout/crlf.c
index 8e77d0845..347c22198 100644
--- a/tests/checkout/crlf.c
+++ b/tests/checkout/crlf.c
@@ -278,6 +278,7 @@ void test_checkout_crlf__autocrlf_true_index_size_is_filtered_size(void)
void test_checkout_crlf__with_ident(void)
{
git_index *index;
+ git_index_entry *entry;
git_blob *blob;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
@@ -310,14 +311,14 @@ void test_checkout_crlf__with_ident(void)
/* check that blobs have $Id$ */
- cl_git_pass(git_blob_lookup(&blob, g_repo,
- & git_index_get_bypath(index, "lf.ident", 0)->id));
+ cl_assert((entry = git_index_get_bypath(index, "lf.ident", 0)));
+ cl_git_pass(git_blob_lookup(&blob, g_repo, &entry->id));
cl_assert_equal_s(
ALL_LF_TEXT_RAW "\n$Id$\n", git_blob_rawcontent(blob));
git_blob_free(blob);
- cl_git_pass(git_blob_lookup(&blob, g_repo,
- & git_index_get_bypath(index, "more2.identcrlf", 0)->id));
+ cl_assert((entry = git_index_get_bypath(index, "more2.identcrlf", 0)));
+ cl_git_pass(git_blob_lookup(&blob, g_repo, &entry->id));
cl_assert_equal_s(
"\n$Id$\n" MORE_CRLF_TEXT_AS_LF, git_blob_rawcontent(blob));
git_blob_free(blob);