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
--- 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)