Skip to contentSkip to conversation

Fix some unintialized variable warnings

PATCH In review Steffan Karger 3 participants 6 messages Aug 20, 2014 – Sep 15, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Fix some unintialized variable warnings

Does not actually change behaviour, but fixes compiler warnings and properly initializing is good habit anyway.

---
 src/openvpn/plugin.c | 2 +-
 src/openvpn/sig.c    | 2 +-
 src/openvpn/socket.c | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
src/openvpn/plugin.c +1 -1
index 0948f23..54c5b52 100644
@@ -291,7 +291,7 @@ plugin_init_item (struct plugin *p, const struct plugin_option *o)
 static void
 plugin_vlog (openvpn_plugin_log_flags_t flags, const char *name, const char *format, va_list arglist)
 {
-  unsigned int msg_flags;
+  unsigned int msg_flags = 0;
 
   if (!format)
     return;
src/openvpn/sig.c +1 -1
index 90e39a4..a3d29de 100644
@@ -126,7 +126,7 @@ print_signal (const struct signal_info *si, const char *title, int msglevel)
     {
       const char *type = (si->signal_text ? si->signal_text : "");
       const char *t = (title ? title : "process");
-      const char *hs;
+      const char *hs = NULL;
       switch (si->source)
         {
         case SIG_SOURCE_SOFT:
src/openvpn/socket.c +2 -2
index 9e6bd10..c649d62 100644
@@ -2354,12 +2354,12 @@ print_sockaddr_ex (const struct sockaddr *sa,
 				   struct gc_arena *gc)
 {
   struct buffer out = alloc_buf_gc (128, gc);
-  bool addr_is_defined;
+  bool addr_is_defined = false;
   char hostaddr[NI_MAXHOST] = "";
   char servname[NI_MAXSERV] = "";
   int status;
 
-  socklen_t salen;
+  socklen_t salen = 0;
   switch(sa->sa_family)
     {
     case AF_INET:
Signature · 1 line
1.9.1
#1 lore raw

PATCH 2/2 Fix clang warning in options.c

fixed warning: expression which evaluates to zero treated as a null pointer constant of type 'struct addrinfo *'

Seems to be innocent, but clang is correct that this is strange. init_tun() expects two pointers, but options_string() tried to feed it two uint32_t values.

---
 src/openvpn/options.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/openvpn/options.c +2 -2
index f536daa..84eb6ed 100644
@@ -2934,8 +2934,8 @@ options_string (const struct options *o,
 		     o->ifconfig_ipv6_local,
 		     o->ifconfig_ipv6_netbits,
 		     o->ifconfig_ipv6_remote,
-		     (in_addr_t)0,
-		     (in_addr_t)0,
+		     NULL,
+		     NULL,
 		     false,
 		     NULL);
       if (tt)
Signature · 1 line
1.9.1
#2 lore raw

Re: [Openvpn-devel] [PATCH 2/2] Fix clang warning in options.c

Quoted 17 lines · Steffan Karger

fixed warning: expression which evaluates to zero treated as a null pointer constant of type 'struct addrinfo *'

Seems to be innocent, but clang is correct that this is strange. init_tun() expects two pointers, but options_string() tried to feed it two uint32_t values.

---
 src/openvpn/options.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/openvpn/options.c +0 -0
index f536daa..84eb6ed 100644

src/openvpn/options.c options_string (const struct options *o, · line 2941

Quoted 10 lines
src/openvpn/options.c +2 -2
@@ -2934,8 +2934,8 @@ options_string (const struct options *o,
 		     o->ifconfig_ipv6_local,
 		     o->ifconfig_ipv6_netbits,
 		     o->ifconfig_ipv6_remote,
-		     (in_addr_t)0,
-		     (in_addr_t)0,
+		     NULL,
+		     NULL,
 		     false,
 		     NULL);
       if (tt)

ACK.

Signature · 3 lines
kind regards,

David Sommerseth
#3 lore raw

[Openvpn-devel] [PATCH applied] Re: Fix clang warning in options.c

In reply to Steffan Karger

Your patch has been applied to the master branch.

commit 555b54cc0f0d6495ff427b9f02ecc3bc8ab73141

Author: Steffan Karger
Date:   Wed Aug 20 23:00:26 2014 +0200
     Fix clang warning in options.c

     Signed-off-by: Steffan Karger <[email protected]...>
     Acked-by: David Sommerseth <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/9004
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#4 lore raw
In reply to Steffan Karger
Quoted 46 lines · Steffan Karger

Does not actually change behaviour, but fixes compiler warnings and properly initializing is good habit anyway.

---
 src/openvpn/plugin.c | 2 +-
 src/openvpn/sig.c    | 2 +-
 src/openvpn/socket.c | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
src/openvpn/plugin.c +1 -1
index 0948f23..54c5b52 100644
@@ -291,7 +291,7 @@ plugin_init_item (struct plugin *p, const struct plugin_option *o)
 static void
 plugin_vlog (openvpn_plugin_log_flags_t flags, const char *name, const char *format, va_list arglist)
 {
-  unsigned int msg_flags;
+  unsigned int msg_flags = 0;
 
   if (!format)
     return;
src/openvpn/sig.c +1 -1
index 90e39a4..a3d29de 100644
@@ -126,7 +126,7 @@ print_signal (const struct signal_info *si, const char *title, int msglevel)
     {
       const char *type = (si->signal_text ? si->signal_text : "");
       const char *t = (title ? title : "process");
-      const char *hs;
+      const char *hs = NULL;
       switch (si->source)
         {
         case SIG_SOURCE_SOFT:
src/openvpn/socket.c +0 -1
index 9e6bd10..c649d62 100644
@@ -2354,12 +2354,12 @@ print_sockaddr_ex (const struct sockaddr *sa,
 				   struct gc_arena *gc)
 {
   struct buffer out = alloc_buf_gc (128, gc);
-  bool addr_is_defined;

src/openvpn/socket.c print_sockaddr_ex (const struct sockaddr *sa, · line 2365

Quoted 10 lines
src/openvpn/socket.c +2 -1
+  bool addr_is_defined = false;
   char hostaddr[NI_MAXHOST] = "";
   char servname[NI_MAXSERV] = "";
   int status;
 
-  socklen_t salen;
+  socklen_t salen = 0;
   switch(sa->sa_family)
     {
     case AF_INET:

ACK. Safe and sane changes.

Signature · 3 lines
kind regards,

David Sommerseth
#5 lore raw
In reply to Steffan Karger

Your patch has been applied to the master branch.

commit 5ead2ae0f32e8e6d879ac0de352214a66a7bb351

Author: Steffan Karger
Date:   Wed Aug 20 23:00:25 2014 +0200
     Fix some unintialized variable warnings

     Signed-off-by: Steffan Karger <[email protected]...>
     Acked-by: David Sommerseth <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/9003
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering