Skip to content
This repository has been archived by the owner on Dec 2, 2019. It is now read-only.

Commit

Permalink
Merge pull request #701 from buserror/fix-out-of-bound-access
Browse files Browse the repository at this point in the history
overview.c: Fix an out of bound access
  • Loading branch information
vurtun committed Jun 29, 2018
2 parents cd1624e + e5dee6b commit 4ce3b6a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion demo/overview.c
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ overview(struct nk_context *ctx)
static int sel_nodes[4];
if (node_select != selected[0]) {
selected[0] = node_select;
for (i = 0; i < 8; ++i)
for (i = 0; i < 4; ++i)
sel_nodes[i] = node_select;
}
nk_layout_row_static(ctx, 18, 100, 1);
Expand Down

2 comments on commit 4ce3b6a

@vtlmks
Copy link

@vtlmks vtlmks commented on 4ce3b6a Aug 3, 2018

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..

@vurtun
Copy link
Owner Author

@vurtun vurtun commented on 4ce3b6a Aug 15, 2018

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.

Please sign in to comment.