]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib: avoid dropping const qualifier during cast
authorChristian Göttsche <cgzones@googlemail.com>
Tue, 28 Feb 2023 14:41:20 +0000 (15:41 +0100)
committerSerge Hallyn <serge@hallyn.com>
Mon, 21 Aug 2023 18:54:27 +0000 (13:54 -0500)
    subordinateio.c:360:20: warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
      360 |         range1 = (*(struct commonio_entry **) p1)->eptr;
          |                    ^
    subordinateio.c:364:20: warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
      364 |         range2 = (*(struct commonio_entry **) p2)->eptr;
          |                    ^

    groupio.c:215:15: warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
      215 |         if ((*(struct commonio_entry **) p1)->eptr == NULL) {
          |               ^
    groupio.c:218:15: warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
      218 |         if ((*(struct commonio_entry **) p2)->eptr == NULL) {
          |               ^
    groupio.c:222:34: warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
      222 |         u1 = ((struct group *) (*(struct commonio_entry **) p1)->eptr)->gr_gid;
          |                                  ^
    groupio.c:223:34: warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
      223 |         u2 = ((struct group *) (*(struct commonio_entry **) p2)->eptr)->gr_gid;
          |                                  ^

    pwio.c:187:15: warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
      187 |         if ((*(struct commonio_entry **) p1)->eptr == NULL)
          |               ^
    pwio.c:189:15: warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
      189 |         if ((*(struct commonio_entry **) p2)->eptr == NULL)
          |               ^
    pwio.c:192:35: warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
      192 |         u1 = ((struct passwd *) (*(struct commonio_entry **) p1)->eptr)->pw_uid;
          |                                   ^
    pwio.c:193:35: warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
      193 |         u2 = ((struct passwd *) (*(struct commonio_entry **) p2)->eptr)->pw_uid;
          |                                   ^

Reviewed-by: Alejandro Colomar <alx@kernel.org>
lib/groupio.c
lib/pwio.c
lib/subordinateio.c

index a2182ee7ce15d80b62e766c865af72704c78d6d5..abad2cbfdbb7043e2d5bd461c250070111cfaee8 100644 (file)
@@ -210,17 +210,25 @@ void __gr_del_entry (const struct commonio_entry *ent)
 
 static int gr_cmp (const void *p1, const void *p2)
 {
+       const struct commonio_entry *const *ce1;
+       const struct commonio_entry *const *ce2;
+       const struct group *g1, *g2;
        gid_t u1, u2;
 
-       if ((*(struct commonio_entry **) p1)->eptr == NULL) {
+       ce1 = p1;
+       g1 = (*ce1)->eptr;
+       if (g1 == NULL) {
                return 1;
        }
-       if ((*(struct commonio_entry **) p2)->eptr == NULL) {
+
+       ce2 = p2;
+       g2 = (*ce2)->eptr;
+       if (g2 == NULL) {
                return -1;
        }
 
-       u1 = ((struct group *) (*(struct commonio_entry **) p1)->eptr)->gr_gid;
-       u2 = ((struct group *) (*(struct commonio_entry **) p2)->eptr)->gr_gid;
+       u1 = g1->gr_gid;
+       u2 = g2->gr_gid;
 
        if (u1 < u2) {
                return -1;
index 0ef4606994b4e67aba72c4bd4694f5bd2148146e..95ed0abcc1dd242f465319faf95d46edafec0562 100644 (file)
@@ -182,15 +182,23 @@ struct commonio_db *__pw_get_db (void)
 
 static int pw_cmp (const void *p1, const void *p2)
 {
+       const struct commonio_entry *const *ce1;
+       const struct commonio_entry *const *ce2;
+       const struct passwd *pw1, *pw2;
        uid_t u1, u2;
 
-       if ((*(struct commonio_entry **) p1)->eptr == NULL)
+       ce1 = p1;
+       pw1 = (*ce1)->eptr;
+       if (pw1 == NULL)
                return 1;
-       if ((*(struct commonio_entry **) p2)->eptr == NULL)
+
+       ce2 = p2;
+       pw2 = (*ce2)->eptr;
+       if (pw2 == NULL)
                return -1;
 
-       u1 = ((struct passwd *) (*(struct commonio_entry **) p1)->eptr)->pw_uid;
-       u2 = ((struct passwd *) (*(struct commonio_entry **) p2)->eptr)->pw_uid;
+       u1 = pw1->pw_uid;
+       u2 = pw2->pw_uid;
 
        if (u1 < u2)
                return -1;
index 4139674f008ce75bc1649392c68540fec089b165..b5f5b91a28b40788b9d19a88aa93854e7c450077 100644 (file)
@@ -352,14 +352,17 @@ void free_subordinate_ranges(struct subordinate_range **ranges, int count)
  */
 static int subordinate_range_cmp (const void *p1, const void *p2)
 {
-       struct subordinate_range *range1, *range2;
+       const struct commonio_entry *const *ce1;
+       const struct commonio_entry *const *ce2;
+       const struct subordinate_range *range1, *range2;
 
-
-       range1 = (*(struct commonio_entry **) p1)->eptr;
+       ce1 = p1;
+       range1 = (*ce1)->eptr;
        if (range1 == NULL)
                return 1;
 
-       range2 = (*(struct commonio_entry **) p2)->eptr;
+       ce2 = p2;
+       range2 = (*ce2)->eptr;
        if (range2 == NULL)
                return -1;