Merge branch 'rs/parse-options-dup-null-fix'

Code cleanup.

* rs/parse-options-dup-null-fix:
  parse-options: avoid arithmetic on pointer that's potentially NULL
maint
Junio C Hamano 2019-12-01 09:04:38 -08:00
commit 406ca29e0d
1 changed files with 2 additions and 1 deletions

View File

@ -161,6 +161,7 @@ int parse_opt_tertiary(const struct option *opt, const char *arg, int unset)

struct option *parse_options_dup(const struct option *o)
{
const struct option *orig = o;
struct option *opts;
int nr = 0;

@ -170,7 +171,7 @@ struct option *parse_options_dup(const struct option *o)
}

ALLOC_ARRAY(opts, nr + 1);
memcpy(opts, o - nr, sizeof(*o) * nr);
COPY_ARRAY(opts, orig, nr);
memset(opts + nr, 0, sizeof(*opts));
opts[nr].type = OPTION_END;
return opts;