[SSSD] [PATCH] Suppress warning maybe-uninitialized
Simo Sorce
simo at redhat.com
Thu Oct 2 19:12:50 UTC 2014
On Thu, 2 Oct 2014 19:33:02 +0200
Lukas Slebodnik <lslebodn at redhat.com> wrote:
> ehlo,
>
> There is a warning with some version of gcc (4.9.1, 4.4.7).
> Warning is not visible with gcc 4.8
> In my opinion, variable "a" should be initialized every time if
> "maps" is not NULL.
I agree that "a" should be intialized every time, in fact I do not
agree with your patch where you set it to be a volatile, it is not.
The main issue here is that the name and way this variable is used is
confusing.
A better way would be to define a locally in the first loop, and in the
function define a better name initialized to a negative value.
the name should probably be called something like base_attr_idx and
intialized as:
int base_attr_idx = 0;
and if the first part of the code finds the base_attr it is looking for
it would simply assing a to it (note we do away with "a" completely).
if (map) {
for (i = 1; i < attrs_num; i++) {
...
}
if (i < attrs_num) {
store = true;
base_attr_idx = i;
...
}
}
then the second for loop where you get the error would be change to:
for (ai = base_attr_idx; ai > 0 && ai < attrs_num; ai++) {
Simo.
> 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
>
>
> You can also see warnin in koji build on fedora 21
> https://kojipkgs.fedoraproject.org//packages/sssd/1.12.1/2.fc21/data/logs/x86_64/build.log
> If you have better idea how to fix this warning I will be glad to
> review your patch.
>
> LS
--
Simo Sorce * Red Hat, Inc * New York
More information about the sssd-devel
mailing list