summaryrefslogtreecommitdiffstats
path: root/src/test/test-install-root.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-04-27 14:09:31 +0200
committerLennart Poettering <lennart@poettering.net>2018-04-27 14:29:06 +0200
commitda6053d0a7c16795e7fac1f9ba6694863918a597 (patch)
tree0bf9555c57e4770f9ac3c189fbfdddc8265432d7 /src/test/test-install-root.c
parenttest: add tests for %j and %J specifier in test-execute (#8838) (diff)
downloadsystemd-da6053d0a7c16795e7fac1f9ba6694863918a597.tar.xz
systemd-da6053d0a7c16795e7fac1f9ba6694863918a597.zip
tree-wide: be more careful with the type of array sizes
Previously we were a bit sloppy with the index and size types of arrays, we'd regularly use unsigned. While I don't think this ever resulted in real issues I think we should be more careful there and follow a stricter regime: unless there's a strong reason not to use size_t for array sizes and indexes, size_t it should be. Any allocations we do ultimately will use size_t anyway, and converting forth and back between unsigned and size_t will always be a source of problems. Note that on 32bit machines "unsigned" and "size_t" are equivalent, and on 64bit machines our arrays shouldn't grow that large anyway, and if they do we have a problem, however that kind of overly large allocation we have protections for usually, but for overflows we do not have that so much, hence let's add it. So yeah, it's a story of the current code being already "good enough", but I think some extra type hygiene is better. This patch tries to be comprehensive, but it probably isn't and I missed a few cases. But I guess we can cover that later as we notice it. Among smaller fixes, this changes: 1. strv_length()' return type becomes size_t 2. the unit file changes array size becomes size_t 3. DNS answer and query array sizes become size_t Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=76745
Diffstat (limited to 'src/test/test-install-root.c')
-rw-r--r--src/test/test-install-root.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/test/test-install-root.c b/src/test/test-install-root.c
index 24eda9c44f..194e483294 100644
--- a/src/test/test-install-root.c
+++ b/src/test/test-install-root.c
@@ -17,7 +17,7 @@ static void test_basic_mask_and_enable(const char *root) {
const char *p;
UnitFileState state;
UnitFileChange *changes = NULL;
- unsigned n_changes = 0;
+ size_t n_changes = 0;
log_set_max_level(LOG_DEBUG);
@@ -158,7 +158,7 @@ static void test_linked_units(const char *root) {
const char *p, *q;
UnitFileState state;
UnitFileChange *changes = NULL;
- unsigned n_changes = 0, i;
+ size_t n_changes = 0, i;
/*
* We'll test three cases here:
@@ -303,7 +303,7 @@ static void test_linked_units(const char *root) {
static void test_default(const char *root) {
_cleanup_free_ char *def = NULL;
UnitFileChange *changes = NULL;
- unsigned n_changes = 0;
+ size_t n_changes = 0;
const char *p;
p = strjoina(root, "/usr/lib/systemd/system/test-default-real.target");
@@ -338,7 +338,7 @@ static void test_default(const char *root) {
static void test_add_dependency(const char *root) {
UnitFileChange *changes = NULL;
- unsigned n_changes = 0;
+ size_t n_changes = 0;
const char *p;
p = strjoina(root, "/usr/lib/systemd/system/real-add-dependency-test-target.target");
@@ -365,7 +365,7 @@ static void test_add_dependency(const char *root) {
static void test_template_enable(const char *root) {
UnitFileChange *changes = NULL;
- unsigned n_changes = 0;
+ size_t n_changes = 0;
UnitFileState state;
const char *p;
@@ -479,7 +479,7 @@ static void test_template_enable(const char *root) {
static void test_indirect(const char *root) {
UnitFileChange *changes = NULL;
- unsigned n_changes = 0;
+ size_t n_changes = 0;
UnitFileState state;
const char *p;
@@ -528,7 +528,7 @@ static void test_indirect(const char *root) {
static void test_preset_and_list(const char *root) {
UnitFileChange *changes = NULL;
- unsigned n_changes = 0, i;
+ size_t n_changes = 0, i;
const char *p, *q;
UnitFileState state;
bool got_yes = false, got_no = false;
@@ -638,7 +638,7 @@ static void test_revert(const char *root) {
const char *p;
UnitFileState state;
UnitFileChange *changes = NULL;
- unsigned n_changes = 0;
+ size_t n_changes = 0;
assert(root);
@@ -687,7 +687,7 @@ static void test_revert(const char *root) {
static void test_preset_order(const char *root) {
UnitFileChange *changes = NULL;
- unsigned n_changes = 0;
+ size_t n_changes = 0;
const char *p;
UnitFileState state;
@@ -758,7 +758,7 @@ static void test_with_dropin(const char *root) {
const char *p;
UnitFileState state;
UnitFileChange *changes = NULL;
- unsigned n_changes = 0;
+ size_t n_changes = 0;
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "with-dropin-1.service", &state) == -ENOENT);
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "with-dropin-2.service", &state) == -ENOENT);
@@ -891,7 +891,7 @@ static void test_with_dropin_template(const char *root) {
const char *p;
UnitFileState state;
UnitFileChange *changes = NULL;
- unsigned n_changes = 0;
+ size_t n_changes = 0;
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "with-dropin-1@.service", &state) == -ENOENT);
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "with-dropin-2@.service", &state) == -ENOENT);