Merge pull request #18852 from yuwata/tree-wide-use-UINT64_MAX

tree-wide: use UINT64_MAX or friends
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2021-03-05 17:51:34 +01:00
committed by GitHub
166 changed files with 621 additions and 619 deletions
+6 -6
View File
@@ -4,7 +4,7 @@
int main(int argc, const char *argv[]) {
_cleanup_bitmap_free_ Bitmap *b = NULL, *b2 = NULL;
unsigned n = (unsigned) -1, i = 0;
unsigned n = UINT_MAX, i = 0;
b = bitmap_new();
assert_se(b);
@@ -59,10 +59,10 @@ int main(int argc, const char *argv[]) {
else if (i == 1)
i = 256;
else if (i == 256)
i = (unsigned) -1;
i = UINT_MAX;
}
assert_se(i == (unsigned) -1);
assert_se(i == UINT_MAX);
i = 0;
@@ -73,10 +73,10 @@ int main(int argc, const char *argv[]) {
else if (i == 1)
i = 256;
else if (i == 256)
i = (unsigned) -1;
i = UINT_MAX;
}
assert_se(i == (unsigned) -1);
assert_se(i == UINT_MAX);
b2 = bitmap_copy(b);
assert_se(b2);
@@ -92,7 +92,7 @@ int main(int argc, const char *argv[]) {
bitmap_free(b2);
b2 = NULL;
assert_se(bitmap_set(b, (unsigned) -1) == -ERANGE);
assert_se(bitmap_set(b, UINT_MAX) == -ERANGE);
bitmap_free(b);
b = NULL;
+1 -1
View File
@@ -59,7 +59,7 @@ static void test_next(const char *input, const char *new_tz, usec_t after, usec_
u = after;
r = calendar_spec_next_usec(c, after, &u);
printf("At: %s\n", r < 0 ? strerror_safe(r) : format_timestamp_style(buf, sizeof buf, u, TIMESTAMP_US));
if (expect != (usec_t)-1)
if (expect != USEC_INFINITY)
assert_se(r >= 0 && u == expect);
else
assert(r == -ENOENT);
+8 -8
View File
@@ -207,7 +207,7 @@ static void test_copy_bytes(void) {
assert_se(pipe2(pipefd, O_CLOEXEC) == 0);
r = copy_bytes(infd, pipefd[1], (uint64_t) -1, 0);
r = copy_bytes(infd, pipefd[1], UINT64_MAX, 0);
assert_se(r == 0);
r = read(pipefd[0], buf, sizeof(buf));
@@ -249,7 +249,7 @@ static void test_copy_bytes_regular_file(const char *src, bool try_reflink, uint
assert_se(fd3 >= 0);
r = copy_bytes(fd, fd2, max_bytes, try_reflink ? COPY_REFLINK : 0);
if (max_bytes == (uint64_t) -1)
if (max_bytes == UINT64_MAX)
assert_se(r == 0);
else
assert_se(IN_SET(r, 0, 1));
@@ -258,14 +258,14 @@ static void test_copy_bytes_regular_file(const char *src, bool try_reflink, uint
assert_se(fstat(fd2, &buf2) == 0);
assert_se((uint64_t) buf2.st_size == MIN((uint64_t) buf.st_size, max_bytes));
if (max_bytes < (uint64_t) -1)
if (max_bytes < UINT64_MAX)
/* Make sure the file is now higher than max_bytes */
assert_se(ftruncate(fd2, max_bytes + 1) == 0);
assert_se(lseek(fd2, 0, SEEK_SET) == 0);
r = copy_bytes(fd2, fd3, max_bytes, try_reflink ? COPY_REFLINK : 0);
if (max_bytes == (uint64_t) -1)
if (max_bytes == UINT64_MAX)
assert_se(r == 0);
else
/* We cannot distinguish between the input being exactly max_bytes
@@ -277,7 +277,7 @@ static void test_copy_bytes_regular_file(const char *src, bool try_reflink, uint
assert_se(fstat(fd3, &buf3) == 0);
if (max_bytes == (uint64_t) -1)
if (max_bytes == UINT64_MAX)
assert_se(buf3.st_size == buf2.st_size);
else
assert_se((uint64_t) buf3.st_size == max_bytes);
@@ -312,7 +312,7 @@ static void test_copy_proc(void) {
assert_se(mkdtemp_malloc(NULL, &p) >= 0);
assert_se(f = path_join(p, "version"));
assert_se(copy_file("/proc/version", f, 0, (mode_t) -1, 0, 0, 0) >= 0);
assert_se(copy_file("/proc/version", f, 0, MODE_INVALID, 0, 0, 0) >= 0);
assert_se(read_one_line_file("/proc/version", &a) >= 0);
assert_se(read_one_line_file(f, &b) >= 0);
@@ -327,8 +327,8 @@ int main(int argc, char *argv[]) {
test_copy_file_fd();
test_copy_tree();
test_copy_bytes();
test_copy_bytes_regular_file(argv[0], false, (uint64_t) -1);
test_copy_bytes_regular_file(argv[0], true, (uint64_t) -1);
test_copy_bytes_regular_file(argv[0], false, UINT64_MAX);
test_copy_bytes_regular_file(argv[0], true, UINT64_MAX);
test_copy_bytes_regular_file(argv[0], false, 1000); /* smaller than copy buffer size */
test_copy_bytes_regular_file(argv[0], true, 1000);
test_copy_bytes_regular_file(argv[0], false, 32000); /* larger than copy buffer size */
+11 -11
View File
@@ -703,28 +703,28 @@ static const char buffer[] =
static void test_read_line_one_file(FILE *f) {
_cleanup_free_ char *line = NULL;
assert_se(read_line(f, (size_t) -1, &line) == 15 && streq(line, "Some test data"));
assert_se(read_line(f, SIZE_MAX, &line) == 15 && streq(line, "Some test data"));
line = mfree(line);
assert_se(read_line(f, (size_t) -1, &line) > 0 && streq(line, "루Non-ascii chars: ąę„”"));
assert_se(read_line(f, SIZE_MAX, &line) > 0 && streq(line, "루Non-ascii chars: ąę„”"));
line = mfree(line);
assert_se(read_line(f, (size_t) -1, &line) == 13 && streq(line, "terminators"));
assert_se(read_line(f, SIZE_MAX, &line) == 13 && streq(line, "terminators"));
line = mfree(line);
assert_se(read_line(f, (size_t) -1, &line) == 15 && streq(line, "and even more"));
assert_se(read_line(f, SIZE_MAX, &line) == 15 && streq(line, "and even more"));
line = mfree(line);
assert_se(read_line(f, (size_t) -1, &line) == 25 && streq(line, "now the same with a NUL"));
assert_se(read_line(f, SIZE_MAX, &line) == 25 && streq(line, "now the same with a NUL"));
line = mfree(line);
assert_se(read_line(f, (size_t) -1, &line) == 10 && streq(line, "and more"));
assert_se(read_line(f, SIZE_MAX, &line) == 10 && streq(line, "and more"));
line = mfree(line);
assert_se(read_line(f, (size_t) -1, &line) == 16 && streq(line, "and even more"));
assert_se(read_line(f, SIZE_MAX, &line) == 16 && streq(line, "and even more"));
line = mfree(line);
assert_se(read_line(f, (size_t) -1, &line) == 20 && streq(line, "and yet even more"));
assert_se(read_line(f, SIZE_MAX, &line) == 20 && streq(line, "and yet even more"));
line = mfree(line);
assert_se(read_line(f, 1024, &line) == 30 && streq(line, "With newlines, and a NUL byte"));
@@ -736,7 +736,7 @@ static void test_read_line_one_file(FILE *f) {
assert_se(read_line(f, 1024, &line) == 14 && streq(line, "an empty line"));
line = mfree(line);
assert_se(read_line(f, (size_t) -1, NULL) == 16);
assert_se(read_line(f, SIZE_MAX, NULL) == 16);
assert_se(read_line(f, 16, &line) == -ENOBUFS);
line = mfree(line);
@@ -819,11 +819,11 @@ static void test_read_line4(void) {
assert_se(f = fmemopen_unlocked((void*) eof_endings[i].string, eof_endings[i].length, "r"));
r = read_line(f, (size_t) -1, &s);
r = read_line(f, SIZE_MAX, &s);
assert_se((size_t) r == eof_endings[i].length);
assert_se(streq_ptr(s, "foo"));
assert_se(read_line(f, (size_t) -1, NULL) == 0); /* Ensure we hit EOF */
assert_se(read_line(f, SIZE_MAX, NULL) == 0); /* Ensure we hit EOF */
}
}
+9 -9
View File
@@ -75,7 +75,7 @@ static void test_multiline(void) {
"lines \n"));
formatted = mfree(formatted);
table_set_cell_height_max(table, (size_t) -1);
table_set_cell_height_max(table, SIZE_MAX);
assert_se(table_format(table, &formatted) >= 0);
fputs(formatted, stdout);
assert_se(streq(formatted,
@@ -131,7 +131,7 @@ static void test_multiline(void) {
" line…\n"));
formatted = mfree(formatted);
table_set_cell_height_max(table, (size_t) -1);
table_set_cell_height_max(table, SIZE_MAX);
assert_se(table_format(table, &formatted) >= 0);
fputs(formatted, stdout);
assert_se(streq(formatted,
@@ -189,7 +189,7 @@ static void test_strv(void) {
"lines \n"));
formatted = mfree(formatted);
table_set_cell_height_max(table, (size_t) -1);
table_set_cell_height_max(table, SIZE_MAX);
assert_se(table_format(table, &formatted) >= 0);
fputs(formatted, stdout);
assert_se(streq(formatted,
@@ -245,7 +245,7 @@ static void test_strv(void) {
" line…\n"));
formatted = mfree(formatted);
table_set_cell_height_max(table, (size_t) -1);
table_set_cell_height_max(table, SIZE_MAX);
assert_se(table_format(table, &formatted) >= 0);
fputs(formatted, stdout);
assert_se(streq(formatted,
@@ -300,7 +300,7 @@ static void test_strv_wrapped(void) {
"three different lines two lines\n"));
formatted = mfree(formatted);
table_set_cell_height_max(table, (size_t) -1);
table_set_cell_height_max(table, SIZE_MAX);
assert_se(table_format(table, &formatted) >= 0);
fputs(formatted, stdout);
assert_se(streq(formatted,
@@ -352,7 +352,7 @@ static void test_strv_wrapped(void) {
" ___7___ ___8___\n"));
formatted = mfree(formatted);
table_set_cell_height_max(table, (size_t) -1);
table_set_cell_height_max(table, SIZE_MAX);
assert_se(table_format(table, &formatted) >= 0);
fputs(formatted, stdout);
assert_se(streq(formatted,
@@ -443,8 +443,8 @@ int main(int argc, char *argv[]) {
formatted = mfree(formatted);
table_set_width(t, (size_t) -1);
assert_se(table_set_sort(t, (size_t) 0, (size_t) 2, (size_t) -1) >= 0);
table_set_width(t, SIZE_MAX);
assert_se(table_set_sort(t, (size_t) 0, (size_t) 2, SIZE_MAX) >= 0);
assert_se(table_format(t, &formatted) >= 0);
printf("%s\n", formatted);
@@ -485,7 +485,7 @@ int main(int argc, char *argv[]) {
formatted = mfree(formatted);
assert_se(table_set_display(t, (size_t) 2, (size_t) 0, (size_t) 2, (size_t) 0, (size_t) 0, (size_t) -1) >= 0);
assert_se(table_set_display(t, (size_t) 2, (size_t) 0, (size_t) 2, (size_t) 0, (size_t) 0, SIZE_MAX) >= 0);
assert_se(table_format(t, &formatted) >= 0);
printf("%s\n", formatted);
+1 -1
View File
@@ -864,7 +864,7 @@ static void test_conservative_rename(void) {
assert_se(access(q, F_OK) < 0 && errno == ENOENT);
/* Check that a manual copy is detected */
assert_se(copy_file(p, q, 0, (mode_t) -1, 0, 0, COPY_REFLINK) >= 0);
assert_se(copy_file(p, q, 0, MODE_INVALID, 0, 0, COPY_REFLINK) >= 0);
assert_se(conservative_renameat(AT_FDCWD, q, AT_FDCWD, p) == 0);
assert_se(access(q, F_OK) < 0 && errno == ENOENT);
+7 -7
View File
@@ -80,7 +80,7 @@ static void test_unhexmem_one(const char *s, size_t l, int retval) {
if (retval == 0) {
char *answer;
if (l == (size_t) -1)
if (l == SIZE_MAX)
l = strlen(s);
assert_se(hex = hexmem(mem, len));
@@ -96,15 +96,15 @@ static void test_unhexmem(void) {
test_unhexmem_one(NULL, 0, 0);
test_unhexmem_one("", 0, 0);
test_unhexmem_one("", (size_t) -1, 0);
test_unhexmem_one(" \n \t\r \t\t \n\n\n", (size_t) -1, 0);
test_unhexmem_one("", SIZE_MAX, 0);
test_unhexmem_one(" \n \t\r \t\t \n\n\n", SIZE_MAX, 0);
test_unhexmem_one(hex_invalid, strlen(hex_invalid), -EINVAL);
test_unhexmem_one(hex_invalid, (size_t) - 1, -EINVAL);
test_unhexmem_one(hex, strlen(hex) - 1, -EPIPE);
test_unhexmem_one(hex, strlen(hex), 0);
test_unhexmem_one(hex, (size_t) -1, 0);
test_unhexmem_one(hex, SIZE_MAX, 0);
test_unhexmem_one(hex_space, strlen(hex_space), 0);
test_unhexmem_one(hex_space, (size_t) -1, 0);
test_unhexmem_one(hex_space, SIZE_MAX, 0);
}
/* https://tools.ietf.org/html/rfc4648#section-10 */
@@ -186,7 +186,7 @@ static void test_unbase32hexmem_one(const char *hex, bool padding, int retval, c
_cleanup_free_ void *mem = NULL;
size_t len;
assert_se(unbase32hexmem(hex, (size_t) -1, padding, &mem, &len) == retval);
assert_se(unbase32hexmem(hex, SIZE_MAX, padding, &mem, &len) == retval);
if (retval == 0) {
char *str;
@@ -279,7 +279,7 @@ static void test_unbase64mem_one(const char *input, const char *output, int ret)
_cleanup_free_ void *buffer = NULL;
size_t size = 0;
assert_se(unbase64mem(input, (size_t) -1, &buffer, &size) == ret);
assert_se(unbase64mem(input, SIZE_MAX, &buffer, &size) == ret);
if (ret >= 0) {
assert_se(size == strlen(output));
+1 -1
View File
@@ -72,7 +72,7 @@ static void test_struct(void) {
assert_se(prioq_peek(q) == NULL);
assert_se(prioq_peek_by_index(q, 0) == NULL);
assert_se(prioq_peek_by_index(q, 1) == NULL);
assert_se(prioq_peek_by_index(q, (unsigned) -1) == NULL);
assert_se(prioq_peek_by_index(q, UINT_MAX) == NULL);
for (i = 0; i < SET_SIZE; i++) {
assert_se(t = new0(struct test, 1));
+3 -3
View File
@@ -75,7 +75,7 @@ static void test_utf8_encoded_valid_unichar(void) {
assert_se(utf8_encoded_valid_unichar("\302\256", 1) == -EINVAL); /* truncated */
assert_se(utf8_encoded_valid_unichar("\302\256", 2) == 2);
assert_se(utf8_encoded_valid_unichar("\302\256", 3) == 2);
assert_se(utf8_encoded_valid_unichar("\302\256", (size_t) -1) == 2);
assert_se(utf8_encoded_valid_unichar("\302\256", SIZE_MAX) == 2);
assert_se(utf8_encoded_valid_unichar("a", 1) == 1);
assert_se(utf8_encoded_valid_unichar("a", 2) == 1);
assert_se(utf8_encoded_valid_unichar("\341\204", 1) == -EINVAL); /* truncated, potentially valid */
@@ -196,7 +196,7 @@ static void test_utf8_n_codepoints(void) {
assert_se(utf8_n_codepoints("串") == 1);
assert_se(utf8_n_codepoints("") == 0);
assert_se(utf8_n_codepoints("…👊🔪💐…") == 5);
assert_se(utf8_n_codepoints("\xF1") == (size_t) -1);
assert_se(utf8_n_codepoints("\xF1") == SIZE_MAX);
}
static void test_utf8_console_width(void) {
@@ -207,7 +207,7 @@ static void test_utf8_console_width(void) {
assert_se(utf8_console_width("串") == 2);
assert_se(utf8_console_width("") == 0);
assert_se(utf8_console_width("…👊🔪💐…") == 8);
assert_se(utf8_console_width("\xF1") == (size_t) -1);
assert_se(utf8_console_width("\xF1") == SIZE_MAX);
}
static void test_utf8_to_utf16(void) {