test: add a few non-null checks to make the static analyzer happy

This commit is contained in:
Peter Hutterer 2024-09-11 11:46:15 +10:00
parent bf03c56300
commit ec031bc4bf
3 changed files with 7 additions and 0 deletions

View file

@ -703,6 +703,7 @@ MUNIT_TEST(test_iobuf_append_fd)
MUNIT_TEST(test_iobuf_append_fd_too_many)
{
_cleanup_fclose_ FILE *fp = tmpfile();
munit_assert_ptr_not_null(fp);
int fd = fileno(fp);
_cleanup_iobuf_ struct iobuf *buf = iobuf_new(20);
@ -732,6 +733,7 @@ MUNIT_TEST(test_iobuf_recv_fd)
_cleanup_close_ int left = fds[0];
_cleanup_close_ int right = fds[1];
_cleanup_fclose_ FILE *fp = tmpfile();
munit_assert_ptr_not_null(fp);
/* actual message data to be sent */
char data[] = "some data\n";
@ -782,7 +784,9 @@ MUNIT_TEST(test_pass_fd)
/* Write some data to the file on it's real fd */
for (size_t idx = 0; idx < ARRAY_LENGTH(fps); idx++) {
_cleanup_free_ char *buf = xaprintf("foo %zu\n", idx);
munit_assert_ptr_not_null(buf);
FILE *fp = fps[idx];
munit_assert_ptr_not_null(fp);
fwrite(buf, strlen(buf) + 1, 1, fp);
fflush(fp);
}

View file

@ -239,6 +239,7 @@ source_enable_write(struct source *source, bool enable)
MUNIT_TEST(test_sink)
{
struct sink *sink = sink_new();
munit_assert_ptr_not_null(sink);
sink_dispatch(sink);
sink_dispatch(sink);

View file

@ -427,6 +427,7 @@ MUNIT_TEST(test_strstrip)
while (t->string) {
char *str;
str = strstrip(t->string, t->what);
munit_assert_ptr_not_null(str);
munit_assert_string_equal(str, t->expected);
free(str);
t++;
@ -521,6 +522,7 @@ MUNIT_TEST(test_cmdline_as_str)
munit_assert_int(len, >=, 0);
cmdline[len] = '\0';
munit_assert_ptr_not_null(from_function);
munit_assert_string_equal(cmdline, from_function);
return MUNIT_OK;