Fixed a buffer overflow.

This commit is contained in:
2021-09-03 07:59:36 -07:00
parent b61c78cec0
commit 4b55ec7b93
12 changed files with 104 additions and 103 deletions

View File

@ -11,10 +11,10 @@
#include "../../poker/player.h"
typedef struct {
label_t labelChips;
label_t labelName;
label_t labelInfo;
} pokerplayerui_t;
typedef struct {
pokerplayerui_t players[POKER_PLAYER_COUNT];
label_t labelGameInfo;
} pokerui_t;

View File

@ -8,31 +8,30 @@
#pragma once
#include "../libs.h"
#define MENU_ITEMS_COLUMNS_MAX 16
#define MENU_ITEMS_ROWS_MAX 128
#define MENU_ITEMS_MAX MENU_ITEMS_COLUMNS_MAX * MENU_ITEMS_ROWS_MAX
/** The maximum number of items a menu can hold */
#define MENU_ITEMS_MAX 32
#define MENU_DIRECTION_DOWN 0x01
#define MENU_DIRECTION_UP 0x02
#define MENU_DIRECTION_LEFT 0x03
#define MENU_DIRECTION_RIGHT 0x04
#define MENU_HOLD_DURATION 1.0
typedef struct _menuitem_t menuitem_t;
typedef struct _menu_t menu_t;
typedef struct {
/** Callback for when menu events are fired. */
typedef void menucallback_t(menu_t *m, menuitem_t *t, uint8_t i, void *user);
typedef struct _menuitem_t {
uint8_t x;
uint8_t y;
uint8_t width;
uint8_t height;
} menuitem_t;
typedef struct {
typedef struct _menu_t {
menuitem_t items[MENU_ITEMS_MAX];
uint8_t itemCount;
uint8_t selected;
uint8_t cursorX;
uint8_t cursorY;
// bool holdAllow;
// float holdLast;
void *user;
menucallback_t *onSelect;
} menu_t;

View File

@ -18,12 +18,19 @@
/** Maximum number of items that the list supports */
#define MENULIST_ITEMS_MAX 32
typedef struct _menulist_t menulist_t;
/** Callback for when a menulist item is selected */
typedef void menulistcallback_t(menulist_t *list, uint8_t i, void *user);
/** Representation of a menu list, a menu with multiple menu items. */
typedef struct {
typedef struct _menulist_t {
float x, y;
char *items[MENULIST_ITEMS_MAX];
label_t labels[MENULIST_ITEMS_MAX];
frame_t frame;
menu_t menu;
rectangle_t selection;
menulistcallback_t *onSelect;
void *user;
} menulist_t;

View File

@ -13,7 +13,7 @@
* @param b Number to modulo with. (a % b)
* @returns The modulo result.
*/
#define mathMod(a,b) (a%b+b)%b
#define mathMod(a,b) ((a)%(b)+(b))%(b)
/**
* Returns the modulous a result for b. Works for floating point numbers.

View File

@ -42,7 +42,7 @@
* @param max Maximum value to generate to. (Exclusive)
* @return Random number between min and max.
*/
#define randRange(n, min, max) (mathMod(n, max - min) + min)
#define randRange(n, min, max) (mathMod(n, (max-min)) + min)
#define randInt32Range(min, max) randRange(randInt32(), min, max)
#define randFloatRange(min, max) (fmod(randFloat(), max- min) + min)