From dd5132e041efabcc404fb3c4ce5075b0f1c84066 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 30 Oct 2019 15:11:36 +0000 Subject: [PATCH 1/6] tests: Tidy up GError assignment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No need to clear it to NULL before every time it’s used, since we assert that it’s never set. This introduces no functional changes. Signed-off-by: Philip Withnall --- gio/tests/live-g-file.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/gio/tests/live-g-file.c b/gio/tests/live-g-file.c index 240fa8b25..df56e9f17 100644 --- a/gio/tests/live-g-file.c +++ b/gio/tests/live-g-file.c @@ -188,7 +188,7 @@ test_create_structure (gconstpointer test_data) GFile *root; GFile *child; gboolean res; - GError *error; + GError *error = NULL; GFileOutputStream *outs; GDataOutputStream *outds; guint i; @@ -241,7 +241,6 @@ test_create_structure (gconstpointer test_data) if ((item.mode > 0) && (posix_compat)) { - error = NULL; res = g_file_set_attribute_uint32 (child, G_FILE_ATTRIBUTE_UNIX_MODE, item.mode, @@ -277,7 +276,6 @@ test_create_structure (gconstpointer test_data) child = g_file_get_child (root, "pattern_file"); g_assert (child != NULL); - error = NULL; outs = g_file_replace (child, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &error); g_assert_no_error (error); @@ -287,11 +285,10 @@ test_create_structure (gconstpointer test_data) g_assert (outds != NULL); for (i = 0; i < PATTERN_FILE_SIZE; i++) { - error = NULL; res = g_data_output_stream_put_byte (outds, i % 256, NULL, &error); g_assert_no_error (error); } - error = NULL; + res = g_output_stream_close (G_OUTPUT_STREAM (outs), NULL, &error); g_assert_no_error (error); g_object_unref (outds); From c25e8ec1f2f556bd76aa1b14a7d4f650ae374343 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 30 Oct 2019 15:12:17 +0000 Subject: [PATCH 2/6] tests: Drop pointless assignments Or turn them into proper error checks. This shuts up some `scan-build` warnings. Signed-off-by: Philip Withnall --- gio/tests/live-g-file.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gio/tests/live-g-file.c b/gio/tests/live-g-file.c index df56e9f17..7638ee5be 100644 --- a/gio/tests/live-g-file.c +++ b/gio/tests/live-g-file.c @@ -202,8 +202,8 @@ test_create_structure (gconstpointer test_data) g_assert (root != NULL); /* create root directory */ - res = g_file_make_directory (root, NULL, NULL); - /* don't care about errors here */ + g_file_make_directory (root, NULL, &error); + g_assert_no_error (error); /* create any other items */ for (i = 0; i < G_N_ELEMENTS (sample_struct); i++) @@ -285,11 +285,11 @@ test_create_structure (gconstpointer test_data) g_assert (outds != NULL); for (i = 0; i < PATTERN_FILE_SIZE; i++) { - res = g_data_output_stream_put_byte (outds, i % 256, NULL, &error); + g_data_output_stream_put_byte (outds, i % 256, NULL, &error); g_assert_no_error (error); } - res = g_output_stream_close (G_OUTPUT_STREAM (outs), NULL, &error); + g_output_stream_close (G_OUTPUT_STREAM (outs), NULL, &error); g_assert_no_error (error); g_object_unref (outds); g_object_unref (outs); From 465b4dadf3148e12f867c920b728136069d1367d Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 30 Oct 2019 15:19:03 +0000 Subject: [PATCH 3/6] tests: Use g_assert_*() rather than g_assert() in live-g-file test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit g_assert() is compiled out by `G_DISABLE_ASSERT` and doesn’t give such useful messages on failure. Signed-off-by: Philip Withnall --- gio/tests/live-g-file.c | 221 ++++++++++++++++++++-------------------- 1 file changed, 110 insertions(+), 111 deletions(-) diff --git a/gio/tests/live-g-file.c b/gio/tests/live-g-file.c index 7638ee5be..1eb0949eb 100644 --- a/gio/tests/live-g-file.c +++ b/gio/tests/live-g-file.c @@ -138,12 +138,12 @@ create_empty_file (GFile * parent, const char *filename, GFileOutputStream *outs; child = g_file_get_child (parent, filename); - g_assert (child != NULL); + g_assert_nonnull (child); error = NULL; outs = g_file_replace (child, NULL, FALSE, create_flags, NULL, &error); g_assert_no_error (error); - g_assert (outs != NULL); + g_assert_nonnull (outs); error = NULL; g_output_stream_close (G_OUTPUT_STREAM (outs), NULL, &error); g_object_unref (outs); @@ -158,10 +158,10 @@ create_empty_dir (GFile * parent, const char *filename) GError *error; child = g_file_get_child (parent, filename); - g_assert (child != NULL); + g_assert_nonnull (child); error = NULL; res = g_file_make_directory (child, NULL, &error); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); g_assert_no_error (error); return child; } @@ -174,10 +174,10 @@ create_symlink (GFile * parent, const char *filename, const char *points_to) GError *error; child = g_file_get_child (parent, filename); - g_assert (child != NULL); + g_assert_nonnull (child); error = NULL; res = g_file_make_symbolic_link (child, points_to, NULL, &error); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); g_assert_no_error (error); return child; } @@ -194,12 +194,12 @@ test_create_structure (gconstpointer test_data) guint i; struct StructureItem item; - g_assert (test_data != NULL); + g_assert_nonnull (test_data); log ("\n Going to create testing structure in '%s'...\n", (char *) test_data); root = g_file_new_for_commandline_arg ((char *) test_data); - g_assert (root != NULL); + g_assert_nonnull (root); /* create root directory */ g_file_make_directory (root, NULL, &error); @@ -237,7 +237,7 @@ test_create_structure (gconstpointer test_data) default: break; } - g_assert (child != NULL); + g_assert_nonnull (child); if ((item.mode > 0) && (posix_compat)) { @@ -246,7 +246,7 @@ test_create_structure (gconstpointer test_data) item.mode, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &error); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); g_assert_no_error (error); } @@ -274,15 +274,15 @@ test_create_structure (gconstpointer test_data) /* create a pattern file */ log (" Creating pattern file..."); child = g_file_get_child (root, "pattern_file"); - g_assert (child != NULL); + g_assert_nonnull (child); outs = g_file_replace (child, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &error); g_assert_no_error (error); - g_assert (outs != NULL); + g_assert_nonnull (outs); outds = g_data_output_stream_new (G_OUTPUT_STREAM (outs)); - g_assert (outds != NULL); + g_assert_nonnull (outds); for (i = 0; i < PATTERN_FILE_SIZE; i++) { g_data_output_stream_put_byte (outds, i % 256, NULL, &error); @@ -309,7 +309,7 @@ file_exists (GFile * parent, const char *filename, gboolean * result) *result = FALSE; child = g_file_get_child (parent, filename); - g_assert (child != NULL); + g_assert_nonnull (child); res = g_file_query_exists (child, NULL); if (result) *result = res; @@ -331,7 +331,7 @@ test_attributes (struct StructureItem item, GFileInfo * info) /* standard::type */ has_attr = g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_TYPE); - g_assert_cmpint (has_attr, ==, TRUE); + g_assert_true (has_attr); ftype = g_file_info_get_file_type (info); g_assert_cmpint (ftype, !=, G_FILE_TYPE_UNKNOWN); g_assert_cmpint (ftype, ==, item.file_type); @@ -351,7 +351,7 @@ test_attributes (struct StructureItem item, GFileInfo * info) can_read = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ); - g_assert_cmpint (can_read, ==, TRUE); + g_assert_true (can_read); } /* access::can-write */ @@ -360,25 +360,25 @@ test_attributes (struct StructureItem item, GFileInfo * info) can_write = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE); - g_assert_cmpint (can_write, ==, TRUE); + g_assert_true (can_write); } /* standard::name */ name = g_file_info_get_name (info); - g_assert (name != NULL); + g_assert_nonnull (name); /* standard::display-name */ display_name = g_file_info_get_display_name (info); - g_assert (display_name != NULL); + g_assert_nonnull (display_name); utf8_valid = g_utf8_validate (display_name, -1, NULL); - g_assert_cmpint (utf8_valid, ==, TRUE); + g_assert_true (utf8_valid); /* standard::edit-name */ edit_name = g_file_info_get_edit_name (info); if (edit_name) { utf8_valid = g_utf8_validate (edit_name, -1, NULL); - g_assert_cmpint (utf8_valid, ==, TRUE); + g_assert_true (utf8_valid); } /* standard::copy-name */ @@ -388,7 +388,7 @@ test_attributes (struct StructureItem item, GFileInfo * info) if (copy_name) { utf8_valid = g_utf8_validate (copy_name, -1, NULL); - g_assert_cmpint (utf8_valid, ==, TRUE); + g_assert_true (utf8_valid); } /* standard::is-symlink */ @@ -412,7 +412,7 @@ test_attributes (struct StructureItem item, GFileInfo * info) is_hidden = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN); - g_assert_cmpint (is_hidden, ==, TRUE); + g_assert_true (is_hidden); } /* unix::is-mountpoint */ @@ -440,14 +440,13 @@ test_initial_structure (gconstpointer test_data) gssize read, total_read; struct StructureItem item; - - g_assert (test_data != NULL); + g_assert_nonnull (test_data); log ("\n Testing sample structure in '%s'...\n", (char *) test_data); root = g_file_new_for_commandline_arg ((char *) test_data); - g_assert (root != NULL); + g_assert_nonnull (root); res = g_file_query_exists (root, NULL); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); /* test the structure */ for (i = 0; i < G_N_ELEMENTS (sample_struct); i++) @@ -460,15 +459,15 @@ test_initial_structure (gconstpointer test_data) log (" Testing file '%s'...\n", item.filename); child = file_exists (root, item.filename, &res); - g_assert (child != NULL); - g_assert_cmpint (res, ==, TRUE); + g_assert_nonnull (child); + g_assert_true (res); error = NULL; info = g_file_query_info (child, "*", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &error); g_assert_no_error (error); - g_assert (info != NULL); + g_assert_nonnull (info); test_attributes (item, info); @@ -479,22 +478,22 @@ test_initial_structure (gconstpointer test_data) /* read and test the pattern file */ log (" Testing pattern file...\n"); child = file_exists (root, "pattern_file", &res); - g_assert (child != NULL); - g_assert_cmpint (res, ==, TRUE); + g_assert_nonnull (child); + g_assert_true (res); error = NULL; info = g_file_query_info (child, "*", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &error); g_assert_no_error (error); - g_assert (info != NULL); + g_assert_nonnull (info); size = g_file_info_get_size (info); g_assert_cmpint (size, ==, PATTERN_FILE_SIZE); g_object_unref (info); error = NULL; ins = g_file_read (child, NULL, &error); - g_assert (ins != NULL); + g_assert_nonnull (ins); g_assert_no_error (error); buffer = g_malloc (PATTERN_FILE_SIZE); @@ -516,7 +515,7 @@ test_initial_structure (gconstpointer test_data) error = NULL; res = g_input_stream_close (G_INPUT_STREAM (ins), NULL, &error); g_assert_no_error (error); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); for (i = 0; i < PATTERN_FILE_SIZE; i++) g_assert_cmpint (*(buffer + i), ==, i % 256); @@ -539,26 +538,26 @@ traverse_recurse_dirs (GFile * parent, GFile * root) guint i; gboolean found; - g_assert (root != NULL); + g_assert_nonnull (root); error = NULL; enumerator = g_file_enumerate_children (parent, "*", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &error); - g_assert (enumerator != NULL); + g_assert_nonnull (enumerator); g_assert_no_error (error); - g_assert (g_file_enumerator_get_container (enumerator) == parent); + g_assert_true (g_file_enumerator_get_container (enumerator) == parent); error = NULL; info = g_file_enumerator_next_file (enumerator, NULL, &error); while ((info) && (!error)) { descend = g_file_enumerator_get_child (enumerator, info); - g_assert (descend != NULL); + g_assert_nonnull (descend); relative_path = g_file_get_relative_path (root, descend); - g_assert (relative_path != NULL); + g_assert_nonnull (relative_path); found = FALSE; for (i = 0; i < G_N_ELEMENTS (sample_struct); i++) @@ -572,7 +571,7 @@ traverse_recurse_dirs (GFile * parent, GFile * root) break; } } - g_assert_cmpint (found, ==, TRUE); + g_assert_true (found); log (" Found file %s, relative to root: %s\n", g_file_info_get_display_name (info), relative_path); @@ -591,9 +590,9 @@ traverse_recurse_dirs (GFile * parent, GFile * root) error = NULL; res = g_file_enumerator_close (enumerator, NULL, &error); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); g_assert_no_error (error); - g_assert (g_file_enumerator_is_closed (enumerator)); + g_assert_true (g_file_enumerator_is_closed (enumerator)); g_object_unref (enumerator); } @@ -604,14 +603,14 @@ test_traverse_structure (gconstpointer test_data) GFile *root; gboolean res; - g_assert (test_data != NULL); + g_assert_nonnull (test_data); log ("\n Traversing through the sample structure in '%s'...\n", (char *) test_data); root = g_file_new_for_commandline_arg ((char *) test_data); - g_assert (root != NULL); + g_assert_nonnull (root); res = g_file_query_exists (root, NULL); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); traverse_recurse_dirs (root, root); @@ -633,13 +632,13 @@ test_enumerate (gconstpointer test_data) struct StructureItem item; - g_assert (test_data != NULL); + g_assert_nonnull (test_data); log ("\n Test enumerate '%s'...\n", (char *) test_data); root = g_file_new_for_commandline_arg ((char *) test_data); - g_assert (root != NULL); + g_assert_nonnull (root); res = g_file_query_exists (root, NULL); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); for (i = 0; i < G_N_ELEMENTS (sample_struct); i++) @@ -656,7 +655,7 @@ test_enumerate (gconstpointer test_data) { log (" Testing file '%s'\n", item.filename); child = g_file_get_child (root, item.filename); - g_assert (child != NULL); + g_assert_nonnull (child); error = NULL; enumerator = g_file_enumerate_children (child, "*", @@ -665,21 +664,21 @@ test_enumerate (gconstpointer test_data) if ((item.extra_flags & TEST_NOT_EXISTS) == TEST_NOT_EXISTS) { - g_assert (enumerator == NULL); + g_assert_null (enumerator); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND); } if ((item.extra_flags & TEST_ENUMERATE_FILE) == TEST_ENUMERATE_FILE) { - g_assert (enumerator == NULL); + g_assert_null (enumerator); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY); } if ((item.extra_flags & TEST_NO_ACCESS) == TEST_NO_ACCESS) { - g_assert (enumerator != NULL); + g_assert_nonnull (enumerator); error = NULL; info = g_file_enumerator_next_file (enumerator, NULL, &error); - g_assert (info == NULL); + g_assert_null (info); g_assert_no_error (error); /* no items should be found, no error should be logged */ } @@ -691,7 +690,7 @@ test_enumerate (gconstpointer test_data) { error = NULL; res = g_file_enumerator_close (enumerator, NULL, &error); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); g_assert_no_error (error); g_object_unref (enumerator); @@ -713,11 +712,11 @@ do_copy_move (GFile * root, struct StructureItem item, const char *target_dir, log (" do_copy_move: '%s' --> '%s'\n", item.filename, target_dir); dst_dir = g_file_get_child (root, target_dir); - g_assert (dst_dir != NULL); + g_assert_nonnull (dst_dir); src_file = g_file_get_child (root, item.filename); - g_assert (src_file != NULL); + g_assert_nonnull (src_file); dst_file = g_file_get_child (dst_dir, item.filename); - g_assert (dst_file != NULL); + g_assert_nonnull (dst_file); error = NULL; if ((item.extra_flags & TEST_COPY) == TEST_COPY) @@ -740,28 +739,28 @@ do_copy_move (GFile * root, struct StructureItem item, const char *target_dir, if (((item.extra_flags & TEST_NOT_EXISTS) != TEST_NOT_EXISTS) && (extra_flags == TEST_ALREADY_EXISTS)) { - g_assert_cmpint (res, ==, FALSE); + g_assert_false (res); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS); } /* target file is a file, overwrite is not set */ else if (((item.extra_flags & TEST_NOT_EXISTS) != TEST_NOT_EXISTS) && (extra_flags == TEST_TARGET_IS_FILE)) { - g_assert_cmpint (res, ==, FALSE); + g_assert_false (res); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY); } /* source file is directory */ else if ((item.extra_flags & TEST_COPY_ERROR_RECURSE) == TEST_COPY_ERROR_RECURSE) { - g_assert_cmpint (res, ==, FALSE); + g_assert_false (res); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_WOULD_RECURSE); } /* source or target path doesn't exist */ else if (((item.extra_flags & TEST_NOT_EXISTS) == TEST_NOT_EXISTS) || (extra_flags == TEST_NOT_EXISTS)) { - g_assert_cmpint (res, ==, FALSE); + g_assert_false (res); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND); } /* source or target path permission denied */ @@ -771,19 +770,19 @@ do_copy_move (GFile * root, struct StructureItem item, const char *target_dir, /* This works for root, see bug #552912 */ if (test_suite && getuid () == 0) { - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); g_assert_no_error (error); } else { - g_assert_cmpint (res, ==, FALSE); + g_assert_false (res); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED); } } /* no error should be found, all exceptions defined above */ else { - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); g_assert_no_error (error); } @@ -806,11 +805,11 @@ test_copy_move (gconstpointer test_data) log ("\n"); - g_assert (test_data != NULL); + g_assert_nonnull (test_data); root = g_file_new_for_commandline_arg ((char *) test_data); - g_assert (root != NULL); + g_assert_nonnull (root); res = g_file_query_exists (root, NULL); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); for (i = 0; i < G_N_ELEMENTS (sample_struct); i++) @@ -896,13 +895,13 @@ test_create (gconstpointer test_data) struct StructureItem item; GFileOutputStream *os; - g_assert (test_data != NULL); + g_assert_nonnull (test_data); log ("\n"); root = g_file_new_for_commandline_arg ((char *) test_data); - g_assert (root != NULL); + g_assert_nonnull (root); res = g_file_query_exists (root, NULL); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); for (i = 0; i < G_N_ELEMENTS (sample_struct); i++) { @@ -915,7 +914,7 @@ test_create (gconstpointer test_data) log (" test_create: '%s'\n", item.filename); child = g_file_get_child (root, item.filename); - g_assert (child != NULL); + g_assert_nonnull (child); error = NULL; os = NULL; @@ -935,12 +934,12 @@ test_create (gconstpointer test_data) if (((item.extra_flags & TEST_NOT_EXISTS) == 0) && ((item.extra_flags & TEST_CREATE) == TEST_CREATE)) { - g_assert (os == NULL); + g_assert_null (os); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS); } else if (item.file_type == G_FILE_TYPE_DIRECTORY) { - g_assert (os == NULL); + g_assert_null (os); if ((item.extra_flags & TEST_CREATE) == TEST_CREATE) g_assert_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS); else @@ -948,7 +947,7 @@ test_create (gconstpointer test_data) } else { - g_assert (os != NULL); + g_assert_nonnull (os); g_assert_no_error (error); } @@ -963,7 +962,7 @@ test_create (gconstpointer test_data) if (error) log (" g_output_stream_close: error %d = %s\n", error->code, error->message); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); g_assert_no_error (error); g_object_unref (os); } @@ -983,13 +982,13 @@ test_open (gconstpointer test_data) struct StructureItem item; GFileInputStream *input_stream; - g_assert (test_data != NULL); + g_assert_nonnull (test_data); log ("\n"); root = g_file_new_for_commandline_arg ((char *) test_data); - g_assert (root != NULL); + g_assert_nonnull (root); res = g_file_query_exists (root, NULL); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); for (i = 0; i < G_N_ELEMENTS (sample_struct); i++) { @@ -1003,7 +1002,7 @@ test_open (gconstpointer test_data) log (" test_open: '%s'\n", item.filename); child = g_file_get_child (root, item.filename); - g_assert (child != NULL); + g_assert_nonnull (child); error = NULL; input_stream = g_file_read (child, NULL, &error); @@ -1011,17 +1010,17 @@ test_open (gconstpointer test_data) ((item.extra_flags & TEST_INVALID_SYMLINK) == TEST_INVALID_SYMLINK)) { - g_assert (input_stream == NULL); + g_assert_null (input_stream); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND); } else if (item.file_type == G_FILE_TYPE_DIRECTORY) { - g_assert (input_stream == NULL); + g_assert_null (input_stream); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY); } else { - g_assert (input_stream != NULL); + g_assert_nonnull (input_stream); g_assert_no_error (error); } @@ -1034,7 +1033,7 @@ test_open (gconstpointer test_data) res = g_input_stream_close (G_INPUT_STREAM (input_stream), NULL, &error); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); g_assert_no_error (error); g_object_unref (input_stream); } @@ -1055,13 +1054,13 @@ test_delete (gconstpointer test_data) struct StructureItem item; gchar *path; - g_assert (test_data != NULL); + g_assert_nonnull (test_data); log ("\n"); root = g_file_new_for_commandline_arg ((char *) test_data); - g_assert (root != NULL); + g_assert_nonnull (root); res = g_file_query_exists (root, NULL); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); for (i = 0; i < G_N_ELEMENTS (sample_struct); i++) { @@ -1074,7 +1073,7 @@ test_delete (gconstpointer test_data) ((item.extra_flags & TEST_DELETE_TRASH) == TEST_DELETE_TRASH)) { child = file_exists (root, item.filename, &res); - g_assert (child != NULL); + g_assert_nonnull (child); /* we don't care about result here */ path = g_file_get_path (child); @@ -1090,17 +1089,17 @@ test_delete (gconstpointer test_data) if ((item.extra_flags & TEST_DELETE_NON_EMPTY) == TEST_DELETE_NON_EMPTY) { - g_assert_cmpint (res, ==, FALSE); + g_assert_false (res); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_EMPTY); } if ((item.extra_flags & TEST_DELETE_FAILURE) == TEST_DELETE_FAILURE) { - g_assert_cmpint (res, ==, FALSE); + g_assert_false (res); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND); } if ((item.extra_flags & TEST_NOT_EXISTS) == TEST_NOT_EXISTS) { - g_assert_cmpint (res, ==, FALSE); + g_assert_false (res); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND); } @@ -1123,12 +1122,12 @@ test_make_directory_with_parents (gconstpointer test_data) gboolean res; GError *error = NULL; - g_assert (test_data != NULL); + g_assert_nonnull (test_data); root = g_file_new_for_commandline_arg ((char *) test_data); - g_assert (root != NULL); + g_assert_nonnull (root); res = g_file_query_exists (root, NULL); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); child = g_file_get_child (root, "a"); grandchild = g_file_get_child (child, "b"); @@ -1138,27 +1137,27 @@ test_make_directory_with_parents (gconstpointer test_data) * depth 1, 2, or 3 */ res = g_file_make_directory_with_parents (child, NULL, &error); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); g_assert_no_error (error); res = g_file_query_exists (child, NULL); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); g_file_delete (child, NULL, NULL); res = g_file_make_directory_with_parents (grandchild, NULL, &error); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); g_assert_no_error (error); res = g_file_query_exists (grandchild, NULL); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); g_file_delete (grandchild, NULL, NULL); g_file_delete (child, NULL, NULL); res = g_file_make_directory_with_parents (greatgrandchild, NULL, &error); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); g_assert_no_error (error); res = g_file_query_exists (greatgrandchild, NULL); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); g_file_delete (greatgrandchild, NULL, NULL); g_file_delete (grandchild, NULL, NULL); @@ -1178,22 +1177,22 @@ test_make_directory_with_parents (gconstpointer test_data) #endif g_file_make_directory (child, NULL, NULL); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); res = g_file_set_attribute_uint32 (child, G_FILE_ATTRIBUTE_UNIX_MODE, S_IRUSR + S_IXUSR, /* -r-x------ */ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); res = g_file_make_directory_with_parents (grandchild, NULL, &error); - g_assert_cmpint (res, ==, FALSE); + g_assert_false (res); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED); g_clear_error (&error); res = g_file_make_directory_with_parents (greatgrandchild, NULL, &error); - g_assert_cmpint (res, ==, FALSE); + g_assert_false (res); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED); g_clear_error (&error); @@ -1215,7 +1214,7 @@ cleanup_dir_recurse (GFile *parent, GFile *root) GFile *descend; char *relative_path; - g_assert (root != NULL); + g_assert_nonnull (root); enumerator = g_file_enumerate_children (parent, "*", @@ -1229,9 +1228,9 @@ cleanup_dir_recurse (GFile *parent, GFile *root) while ((info) && (!error)) { descend = g_file_enumerator_get_child (enumerator, info); - g_assert (descend != NULL); + g_assert_nonnull (descend); relative_path = g_file_get_relative_path (root, descend); - g_assert (relative_path != NULL); + g_assert_nonnull (relative_path); g_free (relative_path); log (" deleting '%s'\n", g_file_info_get_display_name (info)); @@ -1241,7 +1240,7 @@ cleanup_dir_recurse (GFile *parent, GFile *root) error = NULL; res = g_file_delete (descend, NULL, &error); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); g_object_unref (descend); error = NULL; @@ -1253,7 +1252,7 @@ cleanup_dir_recurse (GFile *parent, GFile *root) error = NULL; res = g_file_enumerator_close (enumerator, NULL, &error); - g_assert_cmpint (res, ==, TRUE); + g_assert_true (res); g_assert_no_error (error); g_object_unref (enumerator); @@ -1264,12 +1263,12 @@ prep_clean_structure (gconstpointer test_data) { GFile *root; - g_assert (test_data != NULL); + g_assert_nonnull (test_data); log ("\n Cleaning target testing structure in '%s'...\n", (char *) test_data); root = g_file_new_for_commandline_arg ((char *) test_data); - g_assert (root != NULL); + g_assert_nonnull (root); cleanup_dir_recurse (root, root); From 543a0c40914609f0253fb36ae0c67314fdaa9df5 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 30 Oct 2019 15:24:08 +0000 Subject: [PATCH 4/6] tests: Fix unused variable in the threadpool-test It looks like `continue_timeout` should be returned here, rather than being set and never read. Spotted by `scan-build`. Signed-off-by: Philip Withnall --- tests/threadpool-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/threadpool-test.c b/tests/threadpool-test.c index 1c8aa06d8..b2cb4d99e 100644 --- a/tests/threadpool-test.c +++ b/tests/threadpool-test.c @@ -414,7 +414,7 @@ test_check_start_and_stop (gpointer user_data) } run_next = FALSE; - return TRUE; + return continue_timeout; } if (test_number == 3) { From 15818926b360b99d7897e519d7414470870b2e58 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 30 Oct 2019 15:35:15 +0000 Subject: [PATCH 5/6] glocalfileinfo: Fix minor leak on error handling path for xattrs Spotted by `scan-build`. Signed-off-by: Philip Withnall --- gio/glocalfileinfo.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gio/glocalfileinfo.c b/gio/glocalfileinfo.c index dcc9bce1e..5ba7691a6 100644 --- a/gio/glocalfileinfo.c +++ b/gio/glocalfileinfo.c @@ -504,7 +504,10 @@ get_xattrs (const char *path, } if (list_res_size == -1) - return; + { + g_free (list); + return; + } attr = list; while (list_res_size > 0) From 1111bc4cdef49d2b2bb062f1394873ea64ae5d8f Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 30 Oct 2019 15:37:39 +0000 Subject: [PATCH 6/6] gvariant-parser: Shut up a scan-build warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change a condition from one to an equivalent one to shut up a `scan-build` warning about potentially dereferencing a `NULL` value. This introduces no functional changes, as it’s not actually possible to dereference a `NULL` value here (but `scan-build` can’t link the nullability of `error` to the nullability of `result`). Signed-off-by: Philip Withnall --- glib/gvariant-parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glib/gvariant-parser.c b/glib/gvariant-parser.c index 8a6d4d316..bb5238bea 100644 --- a/glib/gvariant-parser.c +++ b/glib/gvariant-parser.c @@ -2543,7 +2543,7 @@ g_variant_new_parsed_va (const gchar *format, ast_free (ast); } - if (result == NULL) + if (error != NULL) g_error ("g_variant_new_parsed: %s", error->message); if (*stream.stream)