[vpnc-devel] uninitialised variables in vpnc.c
Jukka Salmi
j+vpnc at 2009.salmi.ch
Tue Sep 1 15:13:59 CEST 2009
Hello,
(Joerg, thanks for your nightly commits!)
while building vpnc.c there are some warnings:
[...]
vpnc.c: In function 'lifetime_ipsec_process':
vpnc.c:1173: warning: 'value' may be used uninitialized in this function
vpnc.c: In function 'lifetime_ike_process':
vpnc.c:1146: warning: 'value' may be used uninitialized in this function
[...]
The code fragments causing these warnings are
uint32_t value;
[...]
if (...)
value = ...;
else if (...)
value = ...;
else
assert(0);
[...]
(use value)
[...]
This obviously becomes a problem as soon as NDEBUG is defined.
So, how should this be fixed? By initialising value? By explicitly
calling abort(3) after assert(0)? Or by ignoring the warnings and
adding a comment to the README telling that NDEBUG should never be
defined? ;-)
Regards, Jukka
--
This email fills a much-needed gap in the archives.
-------------- next part --------------
Index: vpnc.c
===================================================================
--- vpnc.c (revision 421)
+++ vpnc.c (working copy)
@@ -1143,7 +1143,7 @@
static void lifetime_ike_process(struct sa_block *s, struct isakmp_attribute *a)
{
- uint32_t value;
+ uint32_t value = 0;
assert(a != NULL);
assert(a->type == IKE_ATTRIB_LIFE_TYPE);
@@ -1170,7 +1170,7 @@
static void lifetime_ipsec_process(struct sa_block *s, struct isakmp_attribute *a)
{
- uint32_t value;
+ uint32_t value = 0;
assert(a != NULL);
assert(a->type == ISAKMP_IPSEC_ATTRIB_SA_LIFE_TYPE);
-------------- next part --------------
Index: vpnc.c
===================================================================
--- vpnc.c (revision 421)
+++ vpnc.c (working copy)
@@ -1156,8 +1156,10 @@
value = a->next->u.attr_16;
else if (a->next->af == isakmp_attr_lots && a->next->u.lots.length == 4)
value = ntohl(*((uint32_t *) a->next->u.lots.data));
- else
+ else {
assert(0);
+ abort();
+ }
DEBUG(2, printf("got ike lifetime attributes: %d %s\n", value,
(a->u.attr_16 == IKE_LIFE_TYPE_SECONDS) ? "seconds" : "kilobyte"));
@@ -1183,8 +1185,10 @@
value = a->next->u.attr_16;
else if (a->next->af == isakmp_attr_lots && a->next->u.lots.length == 4)
value = ntohl(*((uint32_t *) a->next->u.lots.data));
- else
+ else {
assert(0);
+ abort();
+ }
DEBUG(2, printf("got ipsec lifetime attributes: %d %s\n", value,
(a->u.attr_16 == IPSEC_LIFE_SECONDS) ? "seconds" : "kilobyte"));
More information about the vpnc-devel
mailing list