[PATCH v2 1/2] settings: Fix uninitialised use

Bastien Nocera <[email protected]>
Newsgroups dev.linux.lists.ell
Message-ID <[email protected]>
__attribute__(cleanup) variables need to be initialised in situ.

In file included from ell/private.h:8,
                 from ell/settings.c:36:
In function 'auto_free',
    inlined from 'l_settings_set_double' at ell/settings.c:1335:2:
./ell/util.h:265:9: warning: 'buf' may be used uninitialized [-Wmaybe-uninitialized]
  265 |         l_free(*p);
      |         ^~~~~~~~~~
ell/settings.c: In function 'l_settings_set_double':
ell/settings.c:1335:33: note: 'buf' was declared here
 1335 |         L_AUTO_FREE_VAR(char *, buf);
      |                                 ^~~
In function 'auto_free',
    inlined from 'l_settings_set_float' at ell/settings.c:1381:2:
./ell/util.h:265:9: warning: 'buf' may be used uninitialized [-Wmaybe-uninitialized]
  265 |         l_free(*p);
      |         ^~~~~~~~~~
ell/settings.c: In function 'l_settings_set_float':
ell/settings.c:1381:33: note: 'buf' was declared here
 1381 |         L_AUTO_FREE_VAR(char *, buf);
      |                                 ^~~
---
Changes since v1:
- Fix the fix to note create more warnings

 ell/settings.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ell/settings.c b/ell/settings.c
index b46d00bd2899..01307ba72b87 100644
--- a/ell/settings.c
+++ b/ell/settings.c
@@ -1332,7 +1332,7 @@ LIB_EXPORT bool l_settings_set_double(struct l_settings *settings,
 					const char *group_name, const char *key,
 					double in)
 {
-	L_AUTO_FREE_VAR(char *, buf);
+	L_AUTO_FREE_VAR(char *, buf) = NULL;
 
 	buf = l_strdup_printf("%f", in);
 
@@ -1378,7 +1378,7 @@ LIB_EXPORT bool l_settings_set_float(struct l_settings *settings,
 					const char *group_name, const char *key,
 					float in)
 {
-	L_AUTO_FREE_VAR(char *, buf);
+	L_AUTO_FREE_VAR(char *, buf) = NULL;
 
 	buf = l_strdup_printf("%f", (double)in);
 
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.