summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2015-01-26 10:56:40 -0600
committerEdward Thomson <ethomson@edwardthomson.com>2015-01-26 10:56:40 -0600
commit645073b770cbf5a85faab9c44c506ccb61be4185 (patch)
tree0413c4978351af52a22df161cac4edfabea45d14
parentf101a7d4ff11a270487964c480f08d24350842e0 (diff)
parent36e13399c030227d19523d19e3b75073a72cadb3 (diff)
downloadlibgit2-645073b770cbf5a85faab9c44c506ccb61be4185.tar.gz
Merge pull request #2848 from JIghtuse/describe_mem_fix
describe example: fix memory allocation size
-rw-r--r--examples/describe.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/examples/describe.c b/examples/describe.c
index 09a4fd008..72d981153 100644
--- a/examples/describe.c
+++ b/examples/describe.c
@@ -96,7 +96,8 @@ static void parse_options(describe_options *opts, int argc, char **argv)
const char *curr = argv[args.pos];
if (curr[0] != '-') {
- opts->commits = (const char **)realloc((void *)opts->commits, ++opts->commit_count);
+ size_t newsz = ++opts->commit_count * sizeof(opts->commits[0]);
+ opts->commits = (const char **)realloc((void *)opts->commits, newsz);
opts->commits[opts->commit_count - 1] = curr;
} else if (!strcmp(curr, "--all")) {
opts->describe_options.describe_strategy = GIT_DESCRIBE_ALL;
@@ -123,7 +124,8 @@ static void parse_options(describe_options *opts, int argc, char **argv)
}
else {
if (!opts->format_options.dirty_suffix || !opts->format_options.dirty_suffix[0]) {
- opts->commits = (const char **)malloc(++opts->commit_count);
+ size_t sz = ++opts->commit_count * sizeof(opts->commits[0]);
+ opts->commits = (const char **)malloc(sz);
opts->commits[0] = "HEAD";
}
}