Changeset 69511176 in mainline


Ignore:
Timestamp:
2021-06-25T15:28:41Z (4 years ago)
Author:
Martin Decky <martin@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bb14312
Parents:
f5819ca1
Message:

Avoid undefined behavior even more

While the previous implementation no longer suffers from undefined
behavior due to unaligned pointer value, it is still problematic due to
indexing beyond a hypothetical array bound. The assignment of
sizeof(itype) is both an aligned value and does not violate any bounds.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/adt/list.h

    rf5819ca1 r69511176  
    9595
    9696#define list_foreach(list, member, itype, iterator) \
    97         for (itype *iterator = NULL; iterator == NULL; iterator = &((itype *) NULL)[1]) \
     97        for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) sizeof(itype)) \
    9898                for (link_t *_link = (list).head.next; \
    9999                    iterator = list_get_instance(_link, itype, member), \
     
    101101
    102102#define list_foreach_rev(list, member, itype, iterator) \
    103         for (itype *iterator = NULL; iterator == NULL; iterator = &((itype *) NULL)[1]) \
     103        for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) sizeof(itype)) \
    104104                for (link_t *_link = (list).head.prev; \
    105105                    iterator = list_get_instance(_link, itype, member), \
  • uspace/lib/c/include/adt/list.h

    rf5819ca1 r69511176  
    8989
    9090#define list_foreach(list, member, itype, iterator) \
    91         for (itype *iterator = NULL; iterator == NULL; iterator = &((itype *) NULL)[1]) \
     91        for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) sizeof(itype)) \
    9292                for (link_t *_link = (list).head.next; \
    9393                    iterator = list_get_instance(_link, itype, member), \
     
    9595
    9696#define list_foreach_rev(list, member, itype, iterator) \
    97         for (itype *iterator = NULL; iterator == NULL; iterator = &((itype *) NULL)[1]) \
     97        for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) sizeof(itype)) \
    9898                for (link_t *_link = (list).head.prev; \
    9999                    iterator = list_get_instance(_link, itype, member), \
Note: See TracChangeset for help on using the changeset viewer.