diff options
author | Ben Straub <bs@github.com> | 2012-11-29 14:06:40 -0800 |
---|---|---|
committer | Ben Straub <bs@github.com> | 2012-11-30 13:12:14 -0800 |
commit | b81aa2f1deb98eb7f9e60ac96696e69a9a49d8f8 (patch) | |
tree | c9319fc7252b87c183dc6d7ed9296c0e48f50f5a /src/checkout.c | |
parent | f4fc9fdba03dd4975229243d7c1debd00c9d1f18 (diff) | |
download | libgit2-b81aa2f1deb98eb7f9e60ac96696e69a9a49d8f8.tar.gz |
Deploy GIT_CHECKOUT_OPTS_INIT
Diffstat (limited to 'src/checkout.c')
-rw-r--r-- | src/checkout.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/checkout.c b/src/checkout.c index a3166bfa5..2a7ad70be 100644 --- a/src/checkout.c +++ b/src/checkout.c @@ -225,10 +225,12 @@ static int retrieve_symlink_caps(git_repository *repo, bool *can_symlink) static void normalize_options( git_checkout_opts *normalized, git_checkout_opts *proposed) { + git_checkout_opts init_opts = GIT_CHECKOUT_OPTS_INIT; + assert(normalized); if (!proposed) - memset(normalized, 0, sizeof(git_checkout_opts)); + memmove(normalized, &init_opts, sizeof(git_checkout_opts)); else memmove(normalized, proposed, sizeof(git_checkout_opts)); @@ -601,6 +603,19 @@ static int checkout_create_submodules( return 0; } +static bool opts_is_valid_version(git_checkout_opts *opts) +{ + if (!opts) + return true; + + if (opts->version > 0 && opts->version <= GIT_CHECKOUT_OPTS_VERSION) + return true; + + giterr_set(GITERR_INVALID, "Invalid version %d on git_checkout_opts structure", + opts->version); + return false; +} + int git_checkout_index( git_repository *repo, git_index *index, @@ -624,6 +639,11 @@ int git_checkout_index( GIT_DIFF_INCLUDE_UNMODIFIED | GIT_DIFF_INCLUDE_UNTRACKED | GIT_DIFF_INCLUDE_TYPECHANGE | GIT_DIFF_SKIP_BINARY_CHECK; + if (!opts_is_valid_version(opts)) { + error = -1; + goto cleanup; + } + if (opts && opts->paths.count > 0) diff_opts.pathspec = opts->paths; |