userdbctl: fix counting
authorLennart Poettering <lennart@poettering.net>
Fri, 22 Nov 2024 09:11:32 +0000 (10:11 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 29 Nov 2024 13:26:56 +0000 (14:26 +0100)
Fixes: #35294
(cherry picked from commit 7f8a4f12dfea6f644f92788bd9b03983898e9d32)

src/userdb/userdbctl.c

index 1ff7d946f03034b1a7ad02751d188d6137192a8e..c80d4fe0e6bd292598eddb2eb5d3fcb436fcfe38 100644 (file)
@@ -178,7 +178,7 @@ static const struct {
 };
 
 static int table_add_uid_boundaries(Table *table, const UIDRange *p) {
-        int r;
+        int r, n_added = 0;
 
         assert(table);
 
@@ -248,9 +248,11 @@ static int table_add_uid_boundaries(Table *table, const UIDRange *p) {
                                 TABLE_INT, 1); /* sort after any other entry with the same UID */
                 if (r < 0)
                         return table_log_add_error(r);
+
+                n_added += 2;
         }
 
-        return ELEMENTSOF(uid_range_table) * 2;
+        return n_added;
 }
 
 static int add_unavailable_uid(Table *table, uid_t start, uid_t end) {
@@ -539,7 +541,7 @@ static int show_group(GroupRecord *gr, Table *table) {
 }
 
 static int table_add_gid_boundaries(Table *table, const UIDRange *p) {
-        int r;
+        int r, n_added = 0;
 
         assert(table);
 
@@ -603,9 +605,11 @@ static int table_add_gid_boundaries(Table *table, const UIDRange *p) {
                                 TABLE_INT, 1); /* sort after any other entry with the same GID */
                 if (r < 0)
                         return table_log_add_error(r);
+
+                n_added += 2;
         }
 
-        return ELEMENTSOF(uid_range_table) * 2;
+        return n_added;
 }
 
 static int add_unavailable_gid(Table *table, uid_t start, uid_t end) {