Changeset 5e801dc in mainline for uspace/lib/c/generic/async/ports.c


Ignore:
Timestamp:
2019-02-25T14:42:38Z (5 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/lib/c/generic/async/ports.c

    ree8d4d6 r5e801dc  
    103103static hash_table_t interface_hash_table;
    104104
    105 static size_t interface_key_hash(void *key)
    106 {
    107         iface_t iface = *(iface_t *) key;
    108         return iface;
     105static size_t interface_key_hash(const void *key)
     106{
     107        const iface_t *iface = key;
     108        return *iface;
    109109}
    110110
     
    115115}
    116116
    117 static bool interface_key_equal(void *key, const ht_link_t *item)
    118 {
    119         iface_t iface = *(iface_t *) key;
     117static bool interface_key_equal(const void *key, const ht_link_t *item)
     118{
     119        const iface_t *iface = key;
    120120        interface_t *interface = hash_table_get_inst(item, interface_t, link);
    121         return iface == interface->iface;
     121        return *iface == interface->iface;
    122122}
    123123
     
    131131};
    132132
    133 static size_t port_key_hash(void *key)
    134 {
    135         port_id_t port_id = *(port_id_t *) key;
    136         return port_id;
     133static size_t port_key_hash(const void *key)
     134{
     135        const port_id_t *port_id = key;
     136        return *port_id;
    137137}
    138138
     
    143143}
    144144
    145 static bool port_key_equal(void *key, const ht_link_t *item)
    146 {
    147         port_id_t port_id = *(port_id_t *) key;
     145static bool port_key_equal(const void *key, const ht_link_t *item)
     146{
     147        const port_id_t *port_id = key;
    148148        port_t *port = hash_table_get_inst(item, port_t, link);
    149         return port_id == port->id;
     149        return *port_id == port->id;
    150150}
    151151
Note: See TracChangeset for help on using the changeset viewer.