[SSSD] [PATCH] Suppress warning maybe-uninitialized

Lukas Slebodnik lslebodn at redhat.com
Wed Oct 8 07:12:53 UTC 2014


On (08/10/14 00:16), Simo Sorce wrote:
>On Tue, 7 Oct 2014 23:57:34 +0200
>Lukas Slebodnik <lslebodn at redhat.com> wrote:
>
>> -                name = map[a].sys_name;
>> +                name = map[i].sys_name;
>> +                base_attr_idx = 1;
>
>this should be base_attr_idx = i; I think.
>
>
/me facepalms

fixed version attached.

LS
-------------- next part --------------
>From c02592d39178aa700be0dab80f479b8313de129b Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn at redhat.com>
Date: Tue, 7 Oct 2014 23:54:51 +0200
Subject: [PATCH] SDAP: Suppress warning maybe-uninitialized

There is a warning with some version of gcc (4.9.1, 4.4.7).
In my opinion, variable "a" should be initialized every time if
"maps" is not NULL.

src/providers/ldap/sdap.c: In function 'sdap_parse_entry':
src/providers/ldap/sdap.c:481:56: warning: 'a' may be used uninitialized in
                                  this function [-Wmaybe-uninitialized]
                         for (ai = a; ai < attrs_num; ai++) {
                                                        ^
src/providers/ldap/sdap.c:307:9: note: 'a' was declared here
     int a, i, ret, ai;
         ^
  CCLD     libsss_ldap_common.la
---
 src/providers/ldap/sdap.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/providers/ldap/sdap.c b/src/providers/ldap/sdap.c
index 7034b11ed8e3aabdcff94462079484dd3ca53ef9..e428d5f4b112fe81c6f04ee1746fba0aa2bc10e5 100644
--- a/src/providers/ldap/sdap.c
+++ b/src/providers/ldap/sdap.c
@@ -304,7 +304,8 @@ int sdap_parse_entry(TALLOC_CTX *memctx,
     struct ldb_val v;
     char *str;
     int lerrno;
-    int a, i, ret, ai;
+    int i, ret, ai;
+    int base_attr_idx = 0;
     const char *name;
     bool store;
     bool base64;
@@ -403,16 +404,17 @@ int sdap_parse_entry(TALLOC_CTX *memctx,
         }
 
         if (map) {
-            for (a = 1; a < attrs_num; a++) {
+            for (i = 1; i < attrs_num; i++) {
                 /* check if this attr is valid with the chosen schema */
-                if (!map[a].name) continue;
+                if (!map[i].name) continue;
                 /* check if it is an attr we are interested in */
-                if (strcasecmp(base_attr, map[a].name) == 0) break;
+                if (strcasecmp(base_attr, map[i].name) == 0) break;
             }
             /* interesting attr */
-            if (a < attrs_num) {
+            if (i < attrs_num) {
                 store = true;
-                name = map[a].sys_name;
+                name = map[i].sys_name;
+                base_attr_idx = i;
                 if (strcmp(name, SYSDB_SSH_PUBKEY) == 0) {
                     base64 = true;
                 }
@@ -478,7 +480,7 @@ int sdap_parse_entry(TALLOC_CTX *memctx,
                          * attrs in case there is a map. Find all that match
                          * and copy the value
                          */
-                        for (ai = a; ai < attrs_num; ai++) {
+                        for (ai = base_attr_idx; ai < attrs_num; ai++) {
                             /* check if this attr is valid with the chosen
                              * schema */
                             if (!map[ai].name) continue;
-- 
2.1.0



More information about the sssd-devel mailing list