Changeset 5e801dc in mainline for uspace/srv/devman/devtree.c


Ignore:
Timestamp:
2019-02-25T14:42:38Z (6 years ago)
Author:
GitHub <noreply@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a4e78743
Parents:
ee8d4d6
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-02-25 14:42:38)
git-committer:
GitHub <noreply@…> (2019-02-25 14:42:38)
Message:

Indicate and enforce constness of hash table key in certain functions (#158)

The assumption here is that modifying key in the hash/equal functions in something completely unexpected, and not something you would ever want to do intentionally, so it makes sense to disallow it entirely to get that extra level of checking.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/devman/devtree.c

    ree8d4d6 r5e801dc  
    4242/* hash table operations */
    4343
    44 static inline size_t handle_key_hash(void *key)
    45 {
    46         devman_handle_t handle = *(devman_handle_t *)key;
    47         return handle;
     44static inline size_t handle_key_hash(const void *key)
     45{
     46        const devman_handle_t *handle = key;
     47        return *handle;
    4848}
    4949
     
    6060}
    6161
    62 static bool devman_devices_key_equal(void *key, const ht_link_t *item)
    63 {
    64         devman_handle_t handle = *(devman_handle_t *)key;
     62static bool devman_devices_key_equal(const void *key, const ht_link_t *item)
     63{
     64        const devman_handle_t *handle = key;
    6565        dev_node_t *dev = hash_table_get_inst(item, dev_node_t, devman_dev);
    66         return dev->handle == handle;
    67 }
    68 
    69 static bool devman_functions_key_equal(void *key, const ht_link_t *item)
    70 {
    71         devman_handle_t handle = *(devman_handle_t *)key;
     66        return dev->handle == *handle;
     67}
     68
     69static bool devman_functions_key_equal(const void *key, const ht_link_t *item)
     70{
     71        const devman_handle_t *handle = key;
    7272        fun_node_t *fun = hash_table_get_inst(item, fun_node_t, devman_fun);
    73         return fun->handle == handle;
    74 }
    75 
    76 static inline size_t service_id_key_hash(void *key)
    77 {
    78         service_id_t service_id = *(service_id_t *)key;
    79         return service_id;
     73        return fun->handle == *handle;
     74}
     75
     76static inline size_t service_id_key_hash(const void *key)
     77{
     78        const service_id_t *service_id = key;
     79        return *service_id;
    8080}
    8181
     
    8686}
    8787
    88 static bool loc_functions_key_equal(void *key, const ht_link_t *item)
    89 {
    90         service_id_t service_id = *(service_id_t *)key;
     88static bool loc_functions_key_equal(const void *key, const ht_link_t *item)
     89{
     90        const service_id_t *service_id = key;
    9191        fun_node_t *fun = hash_table_get_inst(item, fun_node_t, loc_fun);
    92         return fun->service_id == service_id;
     92        return fun->service_id == *service_id;
    9393}
    9494
Note: See TracChangeset for help on using the changeset viewer.