From feb36e2d5b0edb882e152c1fd958166e22eb0cbd Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 14 Jul 2009 06:06:46 +0200 Subject: [PATCH] Fix stupid false positive warnings about uninitialized variables The GCC check for uninitialized variables is so useful that dealing with the false positives is just a minor inconvenience. The following GCC trick helps to silence them: #define uninitialized_var(x) x = x This way no code obfuscation is needed to compile smoothly and the code stays readable. And the author has to actually think about it. --- src/sms.c | 4 +++- src/smsutil.c | 23 ++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/sms.c b/src/sms.c index 1d001595..7f428f36 100644 --- a/src/sms.c +++ b/src/sms.c @@ -40,6 +40,8 @@ #include "sim.h" #include "smsutil.h" +#define uninitialized_var(x) x = x + #define SMS_MANAGER_INTERFACE "org.ofono.SmsManager" #define SMS_MANAGER_FLAG_CACHED 0x1 @@ -522,7 +524,7 @@ static void sms_dispatch(struct ofono_modem *modem, GSList *sms_list) { GSList *l; const struct sms *sms; - enum sms_charset old_charset; + enum sms_charset uninitialized_var(old_charset); enum sms_class cls; int srcport = -1; int dstport = -1; diff --git a/src/smsutil.c b/src/smsutil.c index 292a3fe9..ad38ed98 100644 --- a/src/smsutil.c +++ b/src/smsutil.c @@ -31,6 +31,8 @@ #include "util.h" #include "smsutil.h" +#define uninitialized_var(x) x = x + void extract_bcd_number(const unsigned char *buf, int len, char *out) { static const char digit_lut[] = "0123456789*#abc\0"; @@ -1435,10 +1437,10 @@ const guint8 *sms_extract_common(const struct sms *sms, gboolean *out_udhi, guint8 *out_max) { const guint8 *ud = NULL; - guint8 udl; - guint8 max; - gboolean udhi; - guint8 dcs; + guint8 uninitialized_var(udl); + guint8 uninitialized_var(max); + gboolean uninitialized_var(udhi); + guint8 uninitialized_var(dcs); switch (sms->type) { case SMS_TYPE_DELIVER: @@ -1752,7 +1754,7 @@ static gboolean extract_app_port_common(struct sms_udh_iter *iter, int *dst, guint8 addr_hdr[4]; int srcport = -1; int dstport = -1; - gboolean is_addr_8bit; + gboolean uninitialized_var(is_addr_8bit); /* According to the specification, we have to use the last * useable header. Also, we have to ignore ports that are reserved: @@ -1838,8 +1840,8 @@ gboolean sms_extract_concatenation(const struct sms *sms, guint16 *ref_num, struct sms_udh_iter iter; enum sms_iei iei; guint8 concat_hdr[4]; - guint16 rn; - guint8 max, seq; + guint16 uninitialized_var(rn); + guint8 uninitialized_var(max), uninitialized_var(seq); gboolean concatenated = FALSE; /* We must ignore the entire user_data header here: @@ -2699,13 +2701,16 @@ char *cbs_decode_text(GSList *cbs_list, char *iso639_lang) { GSList *l; const struct cbs *cbs = cbs_list->data; - enum sms_charset charset; + enum sms_charset uninitialized_var(charset); enum cbs_language lang; - gboolean iso639; + gboolean uninitialized_var(iso639); int bufsize = 0; unsigned char *buf; char *utf8; + if (cbs_list == NULL) + return NULL; + /* CBS can only come from the network, so we're much less lenient * on what we support. Namely we require the same charset to be * used across all pages.