diff options
author | Gabriel F. T. Gomes <gabriel@inconstante.eti.br> | 2017-12-19 15:18:07 -0200 |
---|---|---|
committer | Gabriel F. T. Gomes <gabriel@inconstante.eti.br> | 2017-12-19 15:18:07 -0200 |
commit | 567785e2b50321d02d7682aae085f19dc3404f3d (patch) | |
tree | 53e82c7e00c5a2e7674eeee7627ba17477316c58 /grp/grp-merge.c | |
parent | 0f0074a4f1a3ebddb4d5acbbf71ba7c9a2182a47 (diff) | |
parent | c5b38f2ecec6facf818e3c50ad014be05b52c179 (diff) | |
download | glibc-ibm/2.24/master.tar glibc-ibm/2.24/master.tar.gz glibc-ibm/2.24/master.tar.bz2 glibc-ibm/2.24/master.zip |
Merge branch release/2.24/master into ibm/2.24/masteribm/2.24/master
Diffstat (limited to 'grp/grp-merge.c')
-rw-r--r-- | grp/grp-merge.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/grp/grp-merge.c b/grp/grp-merge.c index 0a1eb38d2c..5f79755798 100644 --- a/grp/grp-merge.c +++ b/grp/grp-merge.c @@ -85,6 +85,14 @@ __copy_grp (const struct group srcgrp, const size_t buflen, } members[i] = NULL; + /* Align for pointers. We can't simply align C because we need to + align destbuf[c]. */ + if ((((uintptr_t)destbuf + c) & (__alignof__(char **) - 1)) != 0) + { + uintptr_t mis_align = ((uintptr_t)destbuf + c) & (__alignof__(char **) - 1); + c += __alignof__(char **) - mis_align; + } + /* Copy the pointers from the members array into the buffer and assign them to the gr_mem member of destgrp. */ destgrp->gr_mem = (char **) &destbuf[c]; @@ -129,7 +137,7 @@ __merge_grp (struct group *savedgrp, char *savedbuf, char *savedend, /* Get the count of group members from the last sizeof (size_t) bytes in the mergegrp buffer. */ - savedmemcount = (size_t) *(savedend - sizeof (size_t)); + savedmemcount = *(size_t *) (savedend - sizeof (size_t)); /* Get the count of new members to add. */ for (memcount = 0; mergegrp->gr_mem[memcount]; memcount++) @@ -168,6 +176,14 @@ __merge_grp (struct group *savedgrp, char *savedbuf, char *savedend, /* Add the NULL-terminator. */ members[savedmemcount + memcount] = NULL; + /* Align for pointers. We can't simply align C because we need to + align savedbuf[c]. */ + if ((((uintptr_t)savedbuf + c) & (__alignof__(char **) - 1)) != 0) + { + uintptr_t mis_align = ((uintptr_t)savedbuf + c) & (__alignof__(char **) - 1); + c += __alignof__(char **) - mis_align; + } + /* Copy the member array back into the buffer after the member list and free the member array. */ savedgrp->gr_mem = (char **) &savedbuf[c]; |