[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] initialize some variables in test to prevent -Wmaybe-uninitialized

From: Daniel Shahaf <d.s_at_daniel.shahaf.name>
Date: Sat, 16 Nov 2013 10:29:34 +0200

Andreas Stieger wrote on Sat, Nov 16, 2013 at 00:08:40 +0000:
> Hello,
>
> just noticed some warnings:
> subversion/tests/libsvn_fs_base/fs-base-test.c:239:6: warning: 'present'
> may be used uninitialized in this function [-Wmaybe-uninitialized] et
> al. Initializing to boolean value that would fail the test if the
> reference wasn't changed in called function at all.
>
> [[[
> * subversion/tests/libsvn_fs/fs-test.c
> (check_entry_present, check_entry_absent),
> subversion/tests/libsvn_fs_base/fs-base-test.c

You need a '*' at the start of this line.

> (check_entry_present, check_entry_absent, check_id_present,
> check_id_absent): initialize variable present to silence
> warning -Wmaybe-uninitialized
> ]]]
>
> Andreas

> Index: subversion/tests/libsvn_fs/fs-test.c
> ===================================================================
> --- subversion/tests/libsvn_fs/fs-test.c (revision 1542431)
> +++ subversion/tests/libsvn_fs/fs-test.c (working copy)
> @@ -1020,7 +1020,7 @@ static svn_error_t *
> check_entry_present(svn_fs_root_t *root, const char *path,
> const char *name, apr_pool_t *pool)
> {
> - svn_boolean_t present;
> + svn_boolean_t present = false;
> SVN_ERR(check_entry(root, path, name, &present, pool));
>
> if (! present)
> @@ -1037,7 +1037,7 @@ static svn_error_t *
> check_entry_absent(svn_fs_root_t *root, const char *path,
> const char *name, apr_pool_t *pool)
> {
> - svn_boolean_t present;
> + svn_boolean_t present = true;
> SVN_ERR(check_entry(root, path, name, &present, pool));
>
> if (present)

Personally I'd consider a tristate here, to allow the initialization to
be the same regardless of the sense of the condition in the 'if'.

If you keep it a boolean, you should use FALSE and TRUE instead; those
are in C89, and 'false'/'true' aren't.

If you make either of those two changes, +1 to commit. (If further
changes are needed, they can be made in subsequent commits.)

Daniel
Received on 2013-11-16 09:30:34 CET

This is an archived mail posted to the Subversion Dev mailing list.