libpwdgrp: use a better estimate of max struct size
authorDenys Vlasenko <vda.linux@googlemail.com>
Sat, 3 Jan 2015 16:53:49 +0000 (17:53 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sat, 3 Jan 2015 16:53:49 +0000 (17:53 +0100)
Previous code's trick with bitwise OR was giving this on 32-bit x86:

sizeof(struct passwd):28
sizeof(struct group):16
sizeof(struct spwd):36
sizeof(struct_result):60

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
libpwdgrp/pwd_grp.c

index 539d2b01fdd1a9a20a95c3beaef86353453676e8..f3fcec85955e9a195cec7624e6fc9eb08049d734 100644 (file)
@@ -45,11 +45,10 @@ struct passdb {
        uint8_t numfields;
        FILE *fp;
        char *malloced;
-       char struct_result[0
-                               | sizeof(struct passwd)
-                               | sizeof(struct group)
-       IF_USE_BB_SHADOW(       | sizeof(struct spwd)  )
-       /* bitwise OR above is poor man's max(a,b,c) */
+       char struct_result[
+               /* Should be max(sizeof passwd,group,spwd), but this will do: */
+               IF_NOT_USE_BB_SHADOW(sizeof(struct passwd))
+               IF_USE_BB_SHADOW(sizeof(struct spwd))
        ];
 };