Skip to content

Commit

Permalink
fix: compare result of G_N_ELEMENTS() with size_t
Browse files Browse the repository at this point in the history
I've been told the actual result of `G_N_ELEMENTS()` is actually
`size_t`, rather than e.g. `unsigned int`, so fix all instances of
the incorrect comparison.

Additionally, don't use a static variable to store the length of
test arrays, since `G_N_ELEMENTS()` is a pre-processor macro anyways.
  • Loading branch information
andyholmes committed Mar 22, 2024
1 parent 420d061 commit 99c8dd0
Show file tree
Hide file tree
Showing 22 changed files with 27 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/libvalent/clipboard/valent-clipboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ valent_clipboard_read_text (ValentClipboard *clipboard,

if (mimetypes != NULL)
{
for (unsigned int i = 0; i < G_N_ELEMENTS (text_mimetypes); i++)
for (size_t i = 0; i < G_N_ELEMENTS (text_mimetypes); i++)
{
const char *text_mimetype = text_mimetypes[i];

Expand Down
2 changes: 1 addition & 1 deletion src/libvalent/device/valent-device-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ valent_device_manager_shutdown (ValentApplicationPlugin *plugin)

if (application != NULL)
{
for (unsigned int i = 0; i < G_N_ELEMENTS (app_actions); i++)
for (size_t i = 0; i < G_N_ELEMENTS (app_actions); i++)
g_action_map_remove_action (G_ACTION_MAP (application),
app_actions[i].name);

Expand Down
2 changes: 1 addition & 1 deletion src/libvalent/ui/valent-menu-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ on_key_pressed (GtkEventControllerKey *controller,

g_assert (VALENT_IS_MENU_LIST (self));

for (unsigned int i = 0; i < G_N_ELEMENTS (activate_keys); i++)
for (size_t i = 0; i < G_N_ELEMENTS (activate_keys); i++)
{
if (activate_keys[i] != keyval)
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/libvalent/ui/valent-ui-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ valent_ui_manager_shutdown (ValentApplicationPlugin *plugin)

application = valent_extension_get_object (VALENT_EXTENSION (plugin));

for (unsigned int i = 0; i < G_N_ELEMENTS (app_actions); i++)
for (size_t i = 0; i < G_N_ELEMENTS (app_actions); i++)
g_action_map_remove_action (G_ACTION_MAP (application), app_actions[i].name);

g_clear_pointer (&self->media_remote, gtk_window_destroy);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/mpris/valent-mpris-player.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ on_player_properties_changed (GDBusProxy *proxy,
g_object_freeze_notify (G_OBJECT (self));
g_variant_dict_init (&dict, changed_properties);

for (unsigned int i = 0; i < G_N_ELEMENTS (player_properties); i++)
for (size_t i = 0; i < G_N_ELEMENTS (player_properties); i++)
{
if (g_variant_dict_contains (&dict, player_properties[i].dbus))
{
Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/battery/test-battery-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ test_battery_plugin_fuzz (ValentTestFixture *fixture,
valent_test_fixture_connect (fixture, TRUE);
g_test_log_set_fatal_handler (valent_test_mute_fuzzing, NULL);

for (unsigned int s = 0; s < G_N_ELEMENTS (schemas); s++)
for (size_t s = 0; s < G_N_ELEMENTS (schemas); s++)
valent_test_fixture_schema_fuzz (fixture, schemas[s]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/clipboard/test-clipboard-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ test_clipboard_plugin_fuzz (ValentTestFixture *fixture,
valent_test_fixture_connect (fixture, TRUE);
g_test_log_set_fatal_handler (valent_test_mute_fuzzing, NULL);

for (unsigned int s = 0; s < G_N_ELEMENTS (schemas); s++)
for (size_t s = 0; s < G_N_ELEMENTS (schemas); s++)
valent_test_fixture_schema_fuzz (fixture, schemas[s]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ test_connectivity_report_plugin_fuzz (ValentTestFixture *fixture,
valent_test_fixture_connect (fixture, TRUE);
g_test_log_set_fatal_handler (valent_test_mute_fuzzing, NULL);

for (unsigned int s = 0; s < G_N_ELEMENTS (schemas); s++)
for (size_t s = 0; s < G_N_ELEMENTS (schemas); s++)
valent_test_fixture_schema_fuzz (fixture, schemas[s]);
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/contacts/test-contacts-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ test_contacts_plugin_fuzz (ValentTestFixture *fixture,
valent_test_fixture_connect (fixture, TRUE);
g_test_log_set_fatal_handler (valent_test_mute_fuzzing, NULL);

for (unsigned int s = 0; s < G_N_ELEMENTS (schemas); s++)
for (size_t s = 0; s < G_N_ELEMENTS (schemas); s++)
valent_test_fixture_schema_fuzz (fixture, schemas[s]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/findmyphone/test-findmyphone-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ test_findmyphone_plugin_fuzz (ValentTestFixture *fixture,
valent_test_fixture_connect (fixture, TRUE);
g_test_log_set_fatal_handler (valent_test_mute_fuzzing, NULL);

for (unsigned int s = 0; s < G_N_ELEMENTS (schemas); s++)
for (size_t s = 0; s < G_N_ELEMENTS (schemas); s++)
valent_test_fixture_schema_fuzz (fixture, schemas[s]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/lock/test-lock-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ test_lock_plugin_fuzz (ValentTestFixture *fixture,
valent_test_fixture_connect (fixture, TRUE);
g_test_log_set_fatal_handler (valent_test_mute_fuzzing, NULL);

for (unsigned int s = 0; s < G_N_ELEMENTS (schemas); s++)
for (size_t s = 0; s < G_N_ELEMENTS (schemas); s++)
valent_test_fixture_schema_fuzz (fixture, schemas[s]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/mousepad/test-mousepad-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ test_mousepad_plugin_fuzz (ValentTestFixture *fixture,
v_assert_packet_true (packet, "state");
json_node_unref (packet);

for (unsigned int s = 0; s < G_N_ELEMENTS (schemas); s++)
for (size_t s = 0; s < G_N_ELEMENTS (schemas); s++)
valent_test_fixture_schema_fuzz (fixture, schemas[s]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/mpris/test-mpris-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ test_mpris_plugin_fuzz (ValentTestFixture *fixture,
valent_test_fixture_connect (fixture, TRUE);
g_test_log_set_fatal_handler (valent_test_mute_fuzzing, NULL);

for (unsigned int s = 0; s < G_N_ELEMENTS (schemas); s++)
for (size_t s = 0; s < G_N_ELEMENTS (schemas); s++)
valent_test_fixture_schema_fuzz (fixture, schemas[s]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/notification/test-notification-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ test_notification_plugin_fuzz (ValentTestFixture *fixture,
valent_test_fixture_connect (fixture, TRUE);
g_test_log_set_fatal_handler (valent_test_mute_fuzzing, NULL);

for (unsigned int s = 0; s < G_N_ELEMENTS (schemas); s++)
for (size_t s = 0; s < G_N_ELEMENTS (schemas); s++)
valent_test_fixture_schema_fuzz (fixture, schemas[s]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/ping/test-ping-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ test_ping_plugin_fuzz (ValentTestFixture *fixture,
valent_test_fixture_connect (fixture, TRUE);
g_test_log_set_fatal_handler (valent_test_mute_fuzzing, NULL);

for (unsigned int s = 0; s < G_N_ELEMENTS (schemas); s++)
for (size_t s = 0; s < G_N_ELEMENTS (schemas); s++)
valent_test_fixture_schema_fuzz (fixture, schemas[s]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/presenter/test-presenter-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ test_presenter_plugin_fuzz (ValentTestFixture *fixture,
valent_test_fixture_connect (fixture, TRUE);
g_test_log_set_fatal_handler (valent_test_mute_fuzzing, NULL);

for (unsigned int s = 0; s < G_N_ELEMENTS (schemas); s++)
for (size_t s = 0; s < G_N_ELEMENTS (schemas); s++)
valent_test_fixture_schema_fuzz (fixture, schemas[s]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/sftp/test-sftp-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ test_sftp_plugin_fuzz (ValentTestFixture *fixture,
valent_test_fixture_connect (fixture, TRUE);
g_test_log_set_fatal_handler (valent_test_mute_fuzzing, NULL);

for (unsigned int s = 0; s < G_N_ELEMENTS (schemas); s++)
for (size_t s = 0; s < G_N_ELEMENTS (schemas); s++)
valent_test_fixture_schema_fuzz (fixture, schemas[s]);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/plugins/share/test-share-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static const char * const test_uris[] = {
"resource:///tests/contact2.vcf",
"resource:///tests/contact3.vcf",
};
static guint n_test_uris = G_N_ELEMENTS (test_uris);
static size_t n_test_uris = G_N_ELEMENTS (test_uris);


static void
Expand Down Expand Up @@ -323,7 +323,7 @@ test_share_plugin_fuzz (ValentTestFixture *fixture,
valent_test_fixture_connect (fixture, TRUE);
g_test_log_set_fatal_handler (valent_test_mute_fuzzing, NULL);

for (unsigned int s = 0; s < G_N_ELEMENTS (schemas); s++)
for (size_t s = 0; s < G_N_ELEMENTS (schemas); s++)
valent_test_fixture_schema_fuzz (fixture, schemas[s]);
}

Expand Down
11 changes: 5 additions & 6 deletions tests/plugins/share/test-share-upload.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ static const char * const test_files[] = {
"resource:///tests/contact2.vcf",
"resource:///tests/contact3.vcf",
};
static guint n_test_files = G_N_ELEMENTS (test_files);


static void
Expand Down Expand Up @@ -48,7 +47,7 @@ on_items_changed (GListModel *model,
g_assert_true (item_type == VALENT_TYPE_TRANSFER);
g_assert_true (n_items == added);

g_assert_cmpint (added, ==, n_test_files);
g_assert_cmpint (added, ==, G_N_ELEMENTS (test_files));
}

static void
Expand Down Expand Up @@ -141,7 +140,7 @@ test_share_upload_multiple (ValentTestFixture *fixture,
files = g_list_store_new (G_TYPE_FILE);
transfer = valent_share_upload_new (fixture->device);

for (unsigned int i = 0; i < n_test_files; i++)
for (size_t i = 0; i < G_N_ELEMENTS (test_files); i++)
{
g_autoptr (GFile) file = NULL;
g_autoptr (GFileInfo) info = NULL;
Expand Down Expand Up @@ -176,18 +175,18 @@ test_share_upload_multiple (ValentTestFixture *fixture,

packet = valent_test_fixture_expect_packet (fixture);
v_assert_packet_type (packet, "kdeconnect.share.request.update");
v_assert_packet_cmpint (packet, "numberOfFiles", ==, n_test_files);
v_assert_packet_cmpint (packet, "numberOfFiles", ==, G_N_ELEMENTS (test_files));
v_assert_packet_cmpint (packet, "totalPayloadSize", ==, total_size);
json_node_unref (packet);

for (unsigned int i = 0; i < n_test_files; i++)
for (size_t i = 0; i < G_N_ELEMENTS (test_files); i++)
{
packet = valent_test_fixture_expect_packet (fixture);
v_assert_packet_type (packet, "kdeconnect.share.request");
v_assert_packet_cmpstr (packet, "filename", ==, file_name[i]);
v_assert_packet_field (packet, "creationTime");
v_assert_packet_field (packet, "lastModified");
v_assert_packet_cmpint (packet, "numberOfFiles", ==, n_test_files);
v_assert_packet_cmpint (packet, "numberOfFiles", ==, G_N_ELEMENTS (test_files));
v_assert_packet_cmpint (packet, "totalPayloadSize", ==, total_size);

g_assert_cmpint (valent_packet_get_payload_size (packet), ==, file_size[i]);
Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/sms/test-sms-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ test_sms_plugin_fuzz (ValentTestFixture *fixture,
valent_test_fixture_connect (fixture, TRUE);
g_test_log_set_fatal_handler (valent_test_mute_fuzzing, NULL);

for (unsigned int s = 0; s < G_N_ELEMENTS (schemas); s++)
for (size_t s = 0; s < G_N_ELEMENTS (schemas); s++)
valent_test_fixture_schema_fuzz (fixture, schemas[s]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/sms/test-sms-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ test_sms_phone_number (void)
VALENT_TEST_CHECK ("Functions `valent_phone_number_normalize()` and "
"`valent_phone_number_equal()` can handle a variety of "
"phone number formats");
for (unsigned int i = 0; i < G_N_ELEMENTS (numbers); i++)
for (size_t i = 0; i < G_N_ELEMENTS (numbers); i++)
{
gboolean equal;

Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/telephony/test-telephony-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ test_telephony_plugin_fuzz (ValentTestFixture *fixture,
valent_test_fixture_connect (fixture, TRUE);
g_test_log_set_fatal_handler (valent_test_mute_fuzzing, NULL);

for (unsigned int s = 0; s < G_N_ELEMENTS (schemas); s++)
for (size_t s = 0; s < G_N_ELEMENTS (schemas); s++)
valent_test_fixture_schema_fuzz (fixture, schemas[s]);
}

Expand Down

0 comments on commit 99c8dd0

Please sign in to comment.