Discussion:
[PATCH] selinux: remove extraneous initialization of slots_used and max_chain_len
Colin King
2017-10-14 14:52:24 UTC
Permalink
From: Colin Ian King <***@canonical.com>

Variables slots_used and max_chain_len are being initialized to zero
twice. Remove the first set of initializations. Cleans up the
clang warnings:

Value stored to 'slots_used' is never read
Value stored to 'max_chain_len' is never read

Signed-off-by: Colin Ian King <***@canonical.com>
---
security/selinux/ss/hashtab.c | 2 --
1 file changed, 2 deletions(-)

diff --git a/security/selinux/ss/hashtab.c b/security/selinux/ss/hashtab.c
index bef7577d1270..622fd50c8b9c 100644
--- a/security/selinux/ss/hashtab.c
+++ b/security/selinux/ss/hashtab.c
@@ -148,8 +148,6 @@ void hashtab_stat(struct hashtab *h, struct hashtab_info *info)
u32 i, chain_len, slots_used, max_chain_len;
struct hashtab_node *cur;

- slots_used = 0;
- max_chain_len = 0;
for (slots_used = max_chain_len = i = 0; i < h->size; i++) {
cur = h->htable[i];
if (cur) {
--
2.14.1
walter harms
2017-10-14 15:07:29 UTC
Permalink
Post by Colin King
Variables slots_used and max_chain_len are being initialized to zero
twice. Remove the first set of initializations. Cleans up the
Value stored to 'slots_used' is never read
Value stored to 'max_chain_len' is never read
---
security/selinux/ss/hashtab.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/security/selinux/ss/hashtab.c b/security/selinux/ss/hashtab.c
index bef7577d1270..622fd50c8b9c 100644
--- a/security/selinux/ss/hashtab.c
+++ b/security/selinux/ss/hashtab.c
@@ -148,8 +148,6 @@ void hashtab_stat(struct hashtab *h, struct hashtab_info *info)
u32 i, chain_len, slots_used, max_chain_len;
struct hashtab_node *cur;
- slots_used = 0;
- max_chain_len = 0;
for (slots_used = max_chain_len = i = 0; i < h->size; i++) {
cur = h->htable[i];
if (cur) {
personally i would remove it from the for() loop. for(i=0;) is a common pattern
but setting variables this way is at least uncommon and does not improve the
readability of the code. not a good example for security related code.

just my 2 cents,
re,
wh
Joe Perches
2017-10-14 15:22:46 UTC
Permalink
Post by Colin King
Variables slots_used and max_chain_len are being initialized to zero
twice. Remove the first set of initializations. Cleans up the
Value stored to 'slots_used' is never read
Value stored to 'max_chain_len' is never read
[]
Post by Colin King
diff --git a/security/selinux/ss/hashtab.c b/security/selinux/ss/hashtab.c
[]
Post by Colin King
@@ -148,8 +148,6 @@ void hashtab_stat(struct hashtab *h, struct hashtab_info *info)
u32 i, chain_len, slots_used, max_chain_len;
struct hashtab_node *cur;
- slots_used = 0;
- max_chain_len = 0;
for (slots_used = max_chain_len = i = 0; i < h->size; i++) {
cur = h->htable[i];
if (cur) {
I think it'd be nicer if the assignments in the loop
were removed instead.

slots_used = 0;
max_chain_len = 0;
for (i = 0; i < h->size; i++) {
etc...
Colin King
2017-10-14 15:38:56 UTC
Permalink
From: Colin Ian King <***@canonical.com>

Variables slots_used and max_chain_len are being initialized to zero
twice. Remove the second set of initializations in the for loop.
Cleans up the clang warnings:

Value stored to 'slots_used' is never read
Value stored to 'max_chain_len' is never read

Signed-off-by: Colin Ian King <***@canonical.com>
---
security/selinux/ss/hashtab.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/security/selinux/ss/hashtab.c b/security/selinux/ss/hashtab.c
index bef7577d1270..e0443f4afea5 100644
--- a/security/selinux/ss/hashtab.c
+++ b/security/selinux/ss/hashtab.c
@@ -150,7 +150,7 @@ void hashtab_stat(struct hashtab *h, struct hashtab_info *info)

slots_used = 0;
max_chain_len = 0;
- for (slots_used = max_chain_len = i = 0; i < h->size; i++) {
+ for (i = 0; i < h->size; i++) {
cur = h->htable[i];
if (cur) {
slots_used++;
--
2.14.1
Paul Moore
2017-10-16 22:42:19 UTC
Permalink
Post by Colin King
Variables slots_used and max_chain_len are being initialized to zero
twice. Remove the second set of initializations in the for loop.
Value stored to 'slots_used' is never read
Value stored to 'max_chain_len' is never read
---
security/selinux/ss/hashtab.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Also merged, thanks.
Post by Colin King
diff --git a/security/selinux/ss/hashtab.c b/security/selinux/ss/hashtab.c
index bef7577d1270..e0443f4afea5 100644
--- a/security/selinux/ss/hashtab.c
+++ b/security/selinux/ss/hashtab.c
@@ -150,7 +150,7 @@ void hashtab_stat(struct hashtab *h, struct hashtab_info *info)
slots_used = 0;
max_chain_len = 0;
- for (slots_used = max_chain_len = i = 0; i < h->size; i++) {
+ for (i = 0; i < h->size; i++) {
cur = h->htable[i];
if (cur) {
slots_used++;
--
2.14.1
--
paul moore
www.paul-moore.com
Loading...