Mercurial > hg
diff contrib/chg/chg.c @ 38198:3c84493556db stable
chg: fix an undefined behavior about memcpy
Spot by Wez Furlong. `memcpy(x, NULL, 0)` is undefined according to [1].
[1]: https://stackoverflow.com/questions/5243012
Differential Revision: https://phab.mercurial-scm.org/D3698
author | Jun Wu <quark@fb.com> |
---|---|
date | Wed, 06 Jun 2018 12:53:26 -0700 |
parents | 9724f54923ec |
children | 04a3ae7aba14 |
line wrap: on
line diff
--- a/contrib/chg/chg.c Wed Jun 06 13:28:49 2018 -0400 +++ b/contrib/chg/chg.c Wed Jun 06 12:53:26 2018 -0700 @@ -220,7 +220,10 @@ const char **argv = mallocx(sizeof(char *) * argsize); memcpy(argv, baseargv, sizeof(baseargv)); - memcpy(argv + baseargvsize, opts->args, sizeof(char *) * opts->argsize); + if (opts->args) { + size_t size = sizeof(char *) * opts->argsize; + memcpy(argv + baseargvsize, opts->args, size); + } argv[argsize - 1] = NULL; if (putenv("CHGINTERNALMARK=") != 0)