Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
libsepol/cil: drop unnecessary casts
`const_hashtab_key_t` is a typedef of `const char *`, so these casts are
not needed.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
  • Loading branch information
cgzones authored and jwcart2 committed Jun 24, 2021
1 parent 0bb8951 commit 2723b8e
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions libsepol/cil/src/cil_strpool.c
Expand Up @@ -47,24 +47,21 @@ static hashtab_t cil_strpool_tab = NULL;

static unsigned int cil_strpool_hash(hashtab_t h, const_hashtab_key_t key)
{
const char *p, *keyp;
const char *p;
size_t size;
unsigned int val;

val = 0;
keyp = (const char*)key;
size = strlen(keyp);
for (p = keyp; ((size_t) (p - keyp)) < size; p++)
size = strlen(key);
for (p = key; ((size_t) (p - key)) < size; p++)
val =
(val << 4 | (val >> (8 * sizeof(unsigned int) - 4))) ^ (*p);
return val & (h->size - 1);
}

static int cil_strpool_compare(hashtab_t h __attribute__ ((unused)), const_hashtab_key_t key1, const_hashtab_key_t key2)
{
const char *keyp1 = (const char*)key1;
const char *keyp2 = (const char*)key2;
return strcmp(keyp1, keyp2);
return strcmp(key1, key2);
}

char *cil_strpool_add(const char *str)
Expand All @@ -73,12 +70,12 @@ char *cil_strpool_add(const char *str)

pthread_mutex_lock(&cil_strpool_mutex);

strpool_ref = hashtab_search(cil_strpool_tab, (hashtab_key_t)str);
strpool_ref = hashtab_search(cil_strpool_tab, str);
if (strpool_ref == NULL) {
int rc;
strpool_ref = cil_malloc(sizeof(*strpool_ref));
strpool_ref->str = cil_strdup(str);
rc = hashtab_insert(cil_strpool_tab, (hashtab_key_t)strpool_ref->str, strpool_ref);
rc = hashtab_insert(cil_strpool_tab, strpool_ref->str, strpool_ref);
if (rc != SEPOL_OK) {
pthread_mutex_unlock(&cil_strpool_mutex);
cil_log(CIL_ERR, "Failed to allocate memory\n");
Expand Down

0 comments on commit 2723b8e

Please sign in to comment.