X Tutup
Skip to content

Commit f5fbe71

Browse files
committed
tree-wide: use UINT64_MAX or friends
1 parent ef1e0b9 commit f5fbe71

File tree

150 files changed

+530
-528
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+530
-528
lines changed

src/analyze/analyze.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ static int dump(int argc, char *argv[], void *userdata) {
13571357
return bus_log_parse_error(r);
13581358

13591359
fflush(stdout);
1360-
return copy_bytes(fd, STDOUT_FILENO, (uint64_t) -1, 0);
1360+
return copy_bytes(fd, STDOUT_FILENO, UINT64_MAX, 0);
13611361
}
13621362

13631363
static int cat_config(int argc, char *argv[], void *userdata) {

src/basic/audit-util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <stdint.h>
66
#include <sys/types.h>
77

8-
#define AUDIT_SESSION_INVALID ((uint32_t) -1)
8+
#define AUDIT_SESSION_INVALID (UINT32_MAX)
99

1010
int audit_session_from_pid(pid_t pid, uint32_t *id);
1111
int audit_loginuid_from_pid(pid_t pid, uid_t *uid);

src/basic/btrfs-util.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -396,18 +396,18 @@ static bool btrfs_ioctl_search_args_inc(struct btrfs_ioctl_search_args *args) {
396396
* comparing. This call increases the counter by one, dealing
397397
* with the overflow between the overflows */
398398

399-
if (args->key.min_offset < (uint64_t) -1) {
399+
if (args->key.min_offset < UINT64_MAX) {
400400
args->key.min_offset++;
401401
return true;
402402
}
403403

404-
if (args->key.min_type < (uint8_t) -1) {
404+
if (args->key.min_type < UINT8_MAX) {
405405
args->key.min_type++;
406406
args->key.min_offset = 0;
407407
return true;
408408
}
409409

410-
if (args->key.min_objectid < (uint64_t) -1) {
410+
if (args->key.min_objectid < UINT64_MAX) {
411411
args->key.min_objectid++;
412412
args->key.min_offset = 0;
413413
args->key.min_type = 0;
@@ -464,11 +464,11 @@ int btrfs_subvol_get_info_fd(int fd, uint64_t subvol_id, BtrfsSubvolInfo *ret) {
464464
.key.max_type = BTRFS_ROOT_ITEM_KEY,
465465

466466
.key.min_offset = 0,
467-
.key.max_offset = (uint64_t) -1,
467+
.key.max_offset = UINT64_MAX,
468468

469469
/* No restrictions on the other components */
470470
.key.min_transid = 0,
471-
.key.max_transid = (uint64_t) -1,
471+
.key.max_transid = UINT64_MAX,
472472
};
473473

474474
bool found = false;
@@ -562,7 +562,7 @@ int btrfs_qgroup_get_quota_fd(int fd, uint64_t qgroupid, BtrfsQuotaInfo *ret) {
562562

563563
/* No restrictions on the other components */
564564
.key.min_transid = 0,
565-
.key.max_transid = (uint64_t) -1,
565+
.key.max_transid = UINT64_MAX,
566566
};
567567

568568
bool found_info = false, found_limit = false;
@@ -624,12 +624,12 @@ int btrfs_qgroup_get_quota_fd(int fd, uint64_t qgroupid, BtrfsQuotaInfo *ret) {
624624
if (le64toh(qli->flags) & BTRFS_QGROUP_LIMIT_MAX_RFER)
625625
ret->referenced_max = le64toh(qli->max_rfer);
626626
else
627-
ret->referenced_max = (uint64_t) -1;
627+
ret->referenced_max = UINT64_MAX;
628628

629629
if (le64toh(qli->flags) & BTRFS_QGROUP_LIMIT_MAX_EXCL)
630630
ret->exclusive_max = le64toh(qli->max_excl);
631631
else
632-
ret->exclusive_max = (uint64_t) -1;
632+
ret->exclusive_max = UINT64_MAX;
633633

634634
found_limit = true;
635635
}
@@ -648,13 +648,13 @@ int btrfs_qgroup_get_quota_fd(int fd, uint64_t qgroupid, BtrfsQuotaInfo *ret) {
648648
return -ENODATA;
649649

650650
if (!found_info) {
651-
ret->referenced = (uint64_t) -1;
652-
ret->exclusive = (uint64_t) -1;
651+
ret->referenced = UINT64_MAX;
652+
ret->exclusive = UINT64_MAX;
653653
}
654654

655655
if (!found_limit) {
656-
ret->referenced_max = (uint64_t) -1;
657-
ret->exclusive_max = (uint64_t) -1;
656+
ret->referenced_max = UINT64_MAX;
657+
ret->exclusive_max = UINT64_MAX;
658658
}
659659

660660
return 0;
@@ -671,7 +671,7 @@ int btrfs_qgroup_get_quota(const char *path, uint64_t qgroupid, BtrfsQuotaInfo *
671671
}
672672

673673
int btrfs_subvol_find_subtree_qgroup(int fd, uint64_t subvol_id, uint64_t *ret) {
674-
uint64_t level, lowest = (uint64_t) -1, lowest_qgroupid = 0;
674+
uint64_t level, lowest = UINT64_MAX, lowest_qgroupid = 0;
675675
_cleanup_free_ uint64_t *qgroups = NULL;
676676
int r, n;
677677

@@ -713,13 +713,13 @@ int btrfs_subvol_find_subtree_qgroup(int fd, uint64_t subvol_id, uint64_t *ret)
713713
if (id != subvol_id)
714714
continue;
715715

716-
if (lowest == (uint64_t) -1 || level < lowest) {
716+
if (lowest == UINT64_MAX || level < lowest) {
717717
lowest_qgroupid = qgroups[i];
718718
lowest = level;
719719
}
720720
}
721721

722-
if (lowest == (uint64_t) -1) {
722+
if (lowest == UINT64_MAX) {
723723
/* No suitable higher-level qgroup found, let's return
724724
* the leaf qgroup instead, and indicate that with the
725725
* return value. */
@@ -1089,7 +1089,7 @@ static int subvol_remove_children(int fd, const char *subvolume, uint64_t subvol
10891089
.key.max_type = BTRFS_ROOT_BACKREF_KEY,
10901090

10911091
.key.min_transid = 0,
1092-
.key.max_transid = (uint64_t) -1,
1092+
.key.max_transid = UINT64_MAX,
10931093
};
10941094

10951095
struct btrfs_ioctl_vol_args vol_args = {};
@@ -1265,7 +1265,7 @@ int btrfs_qgroup_copy_limits(int fd, uint64_t old_qgroupid, uint64_t new_qgroupi
12651265

12661266
/* No restrictions on the other components */
12671267
.key.min_transid = 0,
1268-
.key.max_transid = (uint64_t) -1,
1268+
.key.max_transid = UINT64_MAX,
12691269
};
12701270

12711271
int r;
@@ -1451,7 +1451,7 @@ static int subvol_snapshot_children(
14511451
.key.max_type = BTRFS_ROOT_BACKREF_KEY,
14521452

14531453
.key.min_transid = 0,
1454-
.key.max_transid = (uint64_t) -1,
1454+
.key.max_transid = UINT64_MAX,
14551455
};
14561456

14571457
struct btrfs_ioctl_vol_args_v2 vol_args = {
@@ -1721,10 +1721,10 @@ int btrfs_qgroup_find_parents(int fd, uint64_t qgroupid, uint64_t **ret) {
17211721

17221722
/* No restrictions on the other components */
17231723
.key.min_offset = 0,
1724-
.key.max_offset = (uint64_t) -1,
1724+
.key.max_offset = UINT64_MAX,
17251725

17261726
.key.min_transid = 0,
1727-
.key.max_transid = (uint64_t) -1,
1727+
.key.max_transid = UINT64_MAX,
17281728
};
17291729

17301730
_cleanup_free_ uint64_t *items = NULL;
@@ -1965,10 +1965,10 @@ int btrfs_subvol_get_parent(int fd, uint64_t subvol_id, uint64_t *ret) {
19651965

19661966
/* No restrictions on the other components */
19671967
.key.min_offset = 0,
1968-
.key.max_offset = (uint64_t) -1,
1968+
.key.max_offset = UINT64_MAX,
19691969

19701970
.key.min_transid = 0,
1971-
.key.max_transid = (uint64_t) -1,
1971+
.key.max_transid = UINT64_MAX,
19721972
};
19731973
int r;
19741974

src/basic/capability-util.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ bool capability_quintet_mangle(CapabilityQuintet *q) {
405405

406406
combined = q->effective | q->bounding | q->inheritable | q->permitted;
407407

408-
ambient_supported = q->ambient != (uint64_t) -1;
408+
ambient_supported = q->ambient != UINT64_MAX;
409409
if (ambient_supported)
410410
combined |= q->ambient;
411411

@@ -437,7 +437,7 @@ int capability_quintet_enforce(const CapabilityQuintet *q) {
437437
_cleanup_cap_free_ cap_t c = NULL, modified = NULL;
438438
int r;
439439

440-
if (q->ambient != (uint64_t) -1) {
440+
if (q->ambient != UINT64_MAX) {
441441
bool changed = false;
442442

443443
c = cap_get_proc();
@@ -479,7 +479,7 @@ int capability_quintet_enforce(const CapabilityQuintet *q) {
479479
return r;
480480
}
481481

482-
if (q->inheritable != (uint64_t) -1 || q->permitted != (uint64_t) -1 || q->effective != (uint64_t) -1) {
482+
if (q->inheritable != UINT64_MAX || q->permitted != UINT64_MAX || q->effective != UINT64_MAX) {
483483
bool changed = false;
484484

485485
if (!c) {
@@ -492,7 +492,7 @@ int capability_quintet_enforce(const CapabilityQuintet *q) {
492492
uint64_t m = UINT64_C(1) << i;
493493
cap_value_t cv = (cap_value_t) i;
494494

495-
if (q->inheritable != (uint64_t) -1) {
495+
if (q->inheritable != UINT64_MAX) {
496496
cap_flag_value_t old_value, new_value;
497497

498498
if (cap_get_flag(c, cv, CAP_INHERITABLE, &old_value) < 0) {
@@ -515,7 +515,7 @@ int capability_quintet_enforce(const CapabilityQuintet *q) {
515515
}
516516
}
517517

518-
if (q->permitted != (uint64_t) -1) {
518+
if (q->permitted != UINT64_MAX) {
519519
cap_flag_value_t old_value, new_value;
520520

521521
if (cap_get_flag(c, cv, CAP_PERMITTED, &old_value) < 0) {
@@ -535,7 +535,7 @@ int capability_quintet_enforce(const CapabilityQuintet *q) {
535535
}
536536
}
537537

538-
if (q->effective != (uint64_t) -1) {
538+
if (q->effective != UINT64_MAX) {
539539
cap_flag_value_t old_value, new_value;
540540

541541
if (cap_get_flag(c, cv, CAP_EFFECTIVE, &old_value) < 0) {
@@ -559,7 +559,7 @@ int capability_quintet_enforce(const CapabilityQuintet *q) {
559559
if (changed) {
560560
/* In order to change the bounding caps, we need to keep CAP_SETPCAP for a bit
561561
* longer. Let's add it to our list hence for now. */
562-
if (q->bounding != (uint64_t) -1) {
562+
if (q->bounding != UINT64_MAX) {
563563
cap_value_t cv = CAP_SETPCAP;
564564

565565
modified = cap_dup(c);
@@ -587,7 +587,7 @@ int capability_quintet_enforce(const CapabilityQuintet *q) {
587587
}
588588
}
589589

590-
if (q->bounding != (uint64_t) -1) {
590+
if (q->bounding != UINT64_MAX) {
591591
r = capability_bounding_set_drop(q->bounding, false);
592592
if (r < 0)
593593
return r;

src/basic/capability-util.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "missing_capability.h"
1111
#include "util.h"
1212

13-
#define CAP_ALL (uint64_t) -1
13+
#define CAP_ALL UINT64_MAX
1414

1515
unsigned cap_last_cap(void);
1616
int have_effective_cap(int value);
@@ -49,7 +49,7 @@ bool ambient_capabilities_supported(void);
4949
#define CAP_TO_MASK_CORRECTED(x) (1U << ((x) & 31U))
5050

5151
typedef struct CapabilityQuintet {
52-
/* Stores all five types of capabilities in one go. Note that we use (uint64_t) -1 for unset here. This hence
52+
/* Stores all five types of capabilities in one go. Note that we use UINT64_MAX for unset here. This hence
5353
* needs to be updated as soon as Linux learns more than 63 caps. */
5454
uint64_t effective;
5555
uint64_t bounding;
@@ -60,14 +60,14 @@ typedef struct CapabilityQuintet {
6060

6161
assert_cc(CAP_LAST_CAP < 64);
6262

63-
#define CAPABILITY_QUINTET_NULL { (uint64_t) -1, (uint64_t) -1, (uint64_t) -1, (uint64_t) -1, (uint64_t) -1 }
63+
#define CAPABILITY_QUINTET_NULL { UINT64_MAX, UINT64_MAX, UINT64_MAX, UINT64_MAX, UINT64_MAX }
6464

6565
static inline bool capability_quintet_is_set(const CapabilityQuintet *q) {
66-
return q->effective != (uint64_t) -1 ||
67-
q->bounding != (uint64_t) -1 ||
68-
q->inheritable != (uint64_t) -1 ||
69-
q->permitted != (uint64_t) -1 ||
70-
q->ambient != (uint64_t) -1;
66+
return q->effective != UINT64_MAX ||
67+
q->bounding != UINT64_MAX ||
68+
q->inheritable != UINT64_MAX ||
69+
q->permitted != UINT64_MAX ||
70+
q->ambient != UINT64_MAX;
7171
}
7272

7373
/* Mangles the specified caps quintet taking the current bounding set into account:

src/basic/cgroup-util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1975,7 +1975,7 @@ int cg_kernel_controllers(Set **ret) {
19751975
return r;
19761976

19771977
/* Ignore the header line */
1978-
(void) read_line(f, (size_t) -1, NULL);
1978+
(void) read_line(f, SIZE_MAX, NULL);
19791979

19801980
for (;;) {
19811981
char *controller;

src/basic/cgroup-util.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ CGroupMask get_cpu_accounting_mask(void);
7575
bool cpu_accounting_is_cheap(void);
7676

7777
/* Special values for all weight knobs on unified hierarchy */
78-
#define CGROUP_WEIGHT_INVALID ((uint64_t) -1)
78+
#define CGROUP_WEIGHT_INVALID (UINT64_MAX)
7979
#define CGROUP_WEIGHT_MIN UINT64_C(1)
8080
#define CGROUP_WEIGHT_MAX UINT64_C(10000)
8181
#define CGROUP_WEIGHT_DEFAULT UINT64_C(100)
8282

8383
#define CGROUP_LIMIT_MIN UINT64_C(0)
84-
#define CGROUP_LIMIT_MAX ((uint64_t) -1)
84+
#define CGROUP_LIMIT_MAX (UINT64_MAX)
8585

8686
static inline bool CGROUP_WEIGHT_IS_OK(uint64_t x) {
8787
return
@@ -106,7 +106,7 @@ const char* cgroup_io_limit_type_to_string(CGroupIOLimitType t) _const_;
106106
CGroupIOLimitType cgroup_io_limit_type_from_string(const char *s) _pure_;
107107

108108
/* Special values for the cpu.shares attribute */
109-
#define CGROUP_CPU_SHARES_INVALID ((uint64_t) -1)
109+
#define CGROUP_CPU_SHARES_INVALID (UINT64_MAX)
110110
#define CGROUP_CPU_SHARES_MIN UINT64_C(2)
111111
#define CGROUP_CPU_SHARES_MAX UINT64_C(262144)
112112
#define CGROUP_CPU_SHARES_DEFAULT UINT64_C(1024)
@@ -118,7 +118,7 @@ static inline bool CGROUP_CPU_SHARES_IS_OK(uint64_t x) {
118118
}
119119

120120
/* Special values for the blkio.weight attribute */
121-
#define CGROUP_BLKIO_WEIGHT_INVALID ((uint64_t) -1)
121+
#define CGROUP_BLKIO_WEIGHT_INVALID (UINT64_MAX)
122122
#define CGROUP_BLKIO_WEIGHT_MIN UINT64_C(10)
123123
#define CGROUP_BLKIO_WEIGHT_MAX UINT64_C(1000)
124124
#define CGROUP_BLKIO_WEIGHT_DEFAULT UINT64_C(500)

src/basic/copy.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ int copy_bytes_full(
361361
return r;
362362
}
363363

364-
if (max_bytes != (uint64_t) -1) {
364+
if (max_bytes != UINT64_MAX) {
365365
assert(max_bytes >= (uint64_t) n);
366366
max_bytes -= n;
367367
}
@@ -642,7 +642,7 @@ static int fd_copy_regular(
642642
if (fdt < 0)
643643
return -errno;
644644

645-
r = copy_bytes_full(fdf, fdt, (uint64_t) -1, copy_flags, NULL, NULL, progress, userdata);
645+
r = copy_bytes_full(fdf, fdt, UINT64_MAX, copy_flags, NULL, NULL, progress, userdata);
646646
if (r < 0) {
647647
(void) unlinkat(dt, to, 0);
648648
return r;
@@ -1051,7 +1051,7 @@ int copy_file_fd_full(
10511051
if (fdf < 0)
10521052
return -errno;
10531053

1054-
r = copy_bytes_full(fdf, fdt, (uint64_t) -1, copy_flags, NULL, NULL, progress_bytes, userdata);
1054+
r = copy_bytes_full(fdf, fdt, UINT64_MAX, copy_flags, NULL, NULL, progress_bytes, userdata);
10551055

10561056
(void) copy_times(fdf, fdt, copy_flags);
10571057
(void) copy_xattr(fdf, fdt);
@@ -1081,7 +1081,7 @@ int copy_file_full(
10811081
if (fdf < 0)
10821082
return -errno;
10831083

1084-
if (mode == (mode_t) -1)
1084+
if (mode == MODE_INVALID)
10851085
if (fstat(fdf, &st) < 0)
10861086
return -errno;
10871087

@@ -1092,7 +1092,7 @@ int copy_file_full(
10921092
return r;
10931093
}
10941094
fdt = open(to, flags|O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY,
1095-
mode != (mode_t) -1 ? mode : st.st_mode);
1095+
mode != MODE_INVALID ? mode : st.st_mode);
10961096
if (copy_flags & COPY_MAC_CREATE)
10971097
mac_selinux_create_file_clear();
10981098
if (fdt < 0)
@@ -1102,7 +1102,7 @@ int copy_file_full(
11021102
if (chattr_mask != 0)
11031103
(void) chattr_fd(fdt, chattr_flags, chattr_mask & CHATTR_EARLY_FL, NULL);
11041104

1105-
r = copy_bytes_full(fdf, fdt, (uint64_t) -1, copy_flags, NULL, NULL, progress_bytes, userdata);
1105+
r = copy_bytes_full(fdf, fdt, UINT64_MAX, copy_flags, NULL, NULL, progress_bytes, userdata);
11061106
if (r < 0) {
11071107
close(fdt);
11081108
(void) unlink(to);

src/basic/device-nodes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int encode_devnode_name(const char *str, char *str_enc, size_t len) {
2828
for (i = 0, j = 0; str[i] != '\0'; i++) {
2929
int seqlen;
3030

31-
seqlen = utf8_encoded_valid_unichar(str + i, (size_t) -1);
31+
seqlen = utf8_encoded_valid_unichar(str + i, SIZE_MAX);
3232
if (seqlen > 1) {
3333

3434
if (len-j < (size_t)seqlen)

0 commit comments

Comments
 (0)
X Tutup