]> Savannah Git Hosting - gnulib.git/commitdiff
group-member: minor tweak to omit a *
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 7 Apr 2021 00:45:33 +0000 (17:45 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 7 Apr 2021 00:51:35 +0000 (17:51 -0700)
* lib/group-member.c: Include intprops.h.
(get_group_info): Use INT_MULTIPLY_WRAPV instead of
xalloc_oversized (which does a multiplication) followed by the
same multiplication.  The code was OK as-is; this is just
conceptual simplification, possible now that we have xalloc_count_t.
* modules/group-member: Depend on intprops.

ChangeLog
lib/group-member.c
modules/group-member

index c68da0df85665511e728fdae7ee1f37db6f893db..46496bc756dc6d91af5b93e77c3c82ab8b83778a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2021-04-06  Paul Eggert  <eggert@cs.ucla.edu>
 
+       group-member: minor tweak to omit a *
+       * lib/group-member.c: Include intprops.h.
+       (get_group_info): Use INT_MULTIPLY_WRAPV instead of
+       xalloc_oversized (which does a multiplication) followed by the
+       same multiplication.  The code was OK as-is; this is just
+       conceptual simplification, possible now that we have xalloc_count_t.
+       * modules/group-member: Depend on intprops.
+
        backupfile: less-aggressive buffer growth
        * lib/backupfile.c: Include intprops.h.
        (numbered_backup): Grow buffer by the usual 50%, not 100%.
index 52159016eab0c4c53d6a50d703aa6a7609712322..17bee831b4e8a4d543b8dd5da9e94bf335be2b96 100644 (file)
@@ -25,6 +25,7 @@
 #include <sys/types.h>
 #include <stdlib.h>
 
+#include "intprops.h"
 #include "xalloc-oversized.h"
 
 /* Most processes have no more than this many groups, and for these
@@ -53,10 +54,11 @@ get_group_info (struct group_info *gi)
   if (n_groups < 0)
     {
       int n_group_slots = getgroups (0, NULL);
+      xalloc_count_t nbytes;
       if (0 <= n_group_slots
-          && ! xalloc_oversized (n_group_slots, sizeof *gi->group))
+          && ! INT_MULTIPLY_WRAPV (n_group_slots, sizeof *gi->group, &nbytes))
         {
-          gi->group = malloc (n_group_slots * sizeof *gi->group);
+          gi->group = malloc (nbytes);
           if (gi->group)
             n_groups = getgroups (n_group_slots, gi->group);
         }
index 1b743a33b8bec7602bda9bf4df05fb3b04ebeb3c..aa56ecf7e47b19af1719818fab7e45dd35b6b799 100644 (file)
@@ -9,6 +9,7 @@ Depends-on:
 unistd
 extensions
 getgroups        [test $HAVE_GROUP_MEMBER = 0]
+intprops         [test $HAVE_GROUP_MEMBER = 0]
 xalloc-oversized [test $HAVE_GROUP_MEMBER = 0]
 
 configure.ac: