This repository has been archived by the owner on Dec 2, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #701 from buserror/fix-out-of-bound-access
overview.c: Fix an out of bound access
- Loading branch information
4ce3b6a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A suggestion would be to perhaps use a macro to get the size of the array, like
#define arraysize(array) (sizeof(array) / (sizeof(*array)))
or
#define arraysize(array) (sizeof(array) / (sizeof(array[0])))
to not have this bug.
I think most compilers will convert this macro into a number as the arraysize is known, I've only quickly tested it on godbolt.org(compiler explorer) and visual studio and gcc converts it to a plain number at compilation time..
4ce3b6a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vtlmks yeah the example code is a little bit hacky. In the library itself I would have done exactly what you said.