Switch all malloc() calls in djui to calloc(). Possibly fixes menu bug
This commit is contained in:
parent
c7d05d3950
commit
46bef1aaec
|
@ -175,7 +175,7 @@ static void djui_base_add_child(struct DjuiBase* parent, struct DjuiBase* base)
|
|||
if (parent == NULL) { return; }
|
||||
|
||||
// allocate linked list node
|
||||
struct DjuiBaseChild* baseChild = malloc(sizeof(struct DjuiBaseChild));
|
||||
struct DjuiBaseChild* baseChild = calloc(1, sizeof(struct DjuiBaseChild));
|
||||
baseChild->base = base;
|
||||
baseChild->next = NULL;
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ static void djui_bind_destroy(struct DjuiBase* base) {
|
|||
}
|
||||
|
||||
struct DjuiBind* djui_bind_create(struct DjuiBase* parent, const char* message, unsigned int configKey[]) {
|
||||
struct DjuiBind* bind = malloc(sizeof(struct DjuiBind));
|
||||
struct DjuiBind* bind = calloc(1, sizeof(struct DjuiBind));
|
||||
struct DjuiBase* base = &bind->base;
|
||||
|
||||
bind->configKey = configKey;
|
||||
|
|
|
@ -42,7 +42,7 @@ static void djui_button_destroy(struct DjuiBase* base) {
|
|||
}
|
||||
|
||||
struct DjuiButton* djui_button_create(struct DjuiBase* parent, const char* message) {
|
||||
struct DjuiButton* button = malloc(sizeof(struct DjuiButton));
|
||||
struct DjuiButton* button = calloc(1, sizeof(struct DjuiButton));
|
||||
struct DjuiBase* base = &button->base;
|
||||
|
||||
djui_base_init(parent, base, NULL, djui_button_destroy);
|
||||
|
|
|
@ -93,7 +93,7 @@ struct DjuiChatBox* djui_chat_box_create(void) {
|
|||
gDjuiChatBox = NULL;
|
||||
}
|
||||
|
||||
struct DjuiChatBox* chatBox = malloc(sizeof(struct DjuiChatBox));
|
||||
struct DjuiChatBox* chatBox = calloc(1, sizeof(struct DjuiChatBox));
|
||||
struct DjuiBase* base = &chatBox->base;
|
||||
|
||||
djui_base_init(&gDjuiRoot->base, base, djui_chat_box_render, djui_chat_box_destroy);
|
||||
|
|
|
@ -53,7 +53,7 @@ struct DjuiChatMessage* djui_chat_message_create_from(u8 globalIndex, char* mess
|
|||
}
|
||||
|
||||
struct DjuiChatMessage* djui_chat_message_create(char* message) {
|
||||
struct DjuiChatMessage* chatMessage = malloc(sizeof(struct DjuiChatMessage));
|
||||
struct DjuiChatMessage* chatMessage = calloc(1, sizeof(struct DjuiChatMessage));
|
||||
struct DjuiBase* base = &chatMessage->base;
|
||||
djui_base_init(&gDjuiChatBox->chatFlow->base, base, djui_chat_message_render, djui_chat_message_destroy);
|
||||
djui_base_set_size_type(base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
|
|
|
@ -50,8 +50,8 @@ static void djui_checkbox_destroy(struct DjuiBase* base) {
|
|||
}
|
||||
|
||||
struct DjuiCheckbox* djui_checkbox_create(struct DjuiBase* parent, const char* message, bool* value) {
|
||||
struct DjuiCheckbox* checkbox = malloc(sizeof(struct DjuiCheckbox));
|
||||
struct DjuiBase* base = &checkbox->base;
|
||||
struct DjuiCheckbox* checkbox = calloc(1, sizeof(struct DjuiCheckbox));
|
||||
struct DjuiBase* base = &checkbox->base;
|
||||
|
||||
checkbox->value = value;
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ static void djui_flow_layout_destroy(struct DjuiBase* base) {
|
|||
}
|
||||
|
||||
struct DjuiFlowLayout* djui_flow_layout_create(struct DjuiBase* parent) {
|
||||
struct DjuiFlowLayout* layout = malloc(sizeof(struct DjuiFlowLayout));
|
||||
struct DjuiFlowLayout* layout = calloc(1, sizeof(struct DjuiFlowLayout));
|
||||
struct DjuiBase* base = &layout->base;
|
||||
|
||||
djui_base_init(parent, base, djui_rect_render, djui_flow_layout_destroy);
|
||||
|
|
|
@ -50,7 +50,7 @@ static void djui_image_destroy(struct DjuiBase* base) {
|
|||
}
|
||||
|
||||
struct DjuiImage* djui_image_create(struct DjuiBase* parent, const u8* texture, u16 textureWidth, u16 textureHeight, u16 textureBitSize) {
|
||||
struct DjuiImage* image = malloc(sizeof(struct DjuiImage));
|
||||
struct DjuiImage* image = calloc(1, sizeof(struct DjuiImage));
|
||||
struct DjuiBase* base = &image->base;
|
||||
|
||||
djui_base_init(parent, base, djui_image_render, djui_image_destroy);
|
||||
|
|
|
@ -348,7 +348,7 @@ static void djui_inputbox_on_text_input(struct DjuiBase *base, char* text) {
|
|||
}
|
||||
|
||||
// back up current message
|
||||
char* sMsg = malloc(sizeof(char) * (inputbox->bufferSize));
|
||||
char* sMsg = calloc(inputbox->bufferSize, sizeof(char));
|
||||
memcpy(sMsg, msg, inputbox->bufferSize);
|
||||
|
||||
// insert text
|
||||
|
@ -534,12 +534,10 @@ static void djui_inputbox_destroy(struct DjuiBase* base) {
|
|||
}
|
||||
|
||||
struct DjuiInputbox* djui_inputbox_create(struct DjuiBase* parent, u16 bufferSize) {
|
||||
struct DjuiInputbox* inputbox = malloc(sizeof(struct DjuiInputbox));
|
||||
struct DjuiInputbox* inputbox = calloc(1, sizeof(struct DjuiInputbox));
|
||||
struct DjuiBase* base = &inputbox->base;
|
||||
memset(inputbox, 0, sizeof(struct DjuiInputbox));
|
||||
inputbox->bufferSize = bufferSize;
|
||||
inputbox->buffer = malloc(sizeof(char) * bufferSize);
|
||||
memset(inputbox->buffer, 0, sizeof(char) * bufferSize);
|
||||
inputbox->buffer = calloc(bufferSize, sizeof(char));
|
||||
|
||||
djui_base_init(parent, base, djui_inputbox_render, djui_inputbox_destroy);
|
||||
djui_base_set_size(base, 200, 32);
|
||||
|
|
|
@ -430,7 +430,7 @@ void djui_interactable_create(struct DjuiBase* base) {
|
|||
free(base->interactable);
|
||||
}
|
||||
|
||||
struct DjuiInteractable* interactable = malloc(sizeof(struct DjuiInteractable));
|
||||
struct DjuiInteractable* interactable = calloc(1, sizeof(struct DjuiInteractable));
|
||||
memset(interactable, 0, sizeof(struct DjuiInteractable));
|
||||
base->interactable = interactable;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ void djui_panel_add(struct DjuiBase* caller, struct DjuiBase* panelBase, struct
|
|||
}
|
||||
|
||||
// allocate panel
|
||||
struct DjuiPanel* panel = malloc(sizeof(struct DjuiPanel));
|
||||
struct DjuiPanel* panel = calloc(1, sizeof(struct DjuiPanel));
|
||||
panel->parent = sPanelList;
|
||||
panel->base = panelBase;
|
||||
panel->defaultElementBase = defaultElementBase;
|
||||
|
|
|
@ -58,7 +58,7 @@ void djui_panel_host_message_create(struct DjuiBase* caller) {
|
|||
#endif
|
||||
{
|
||||
warningLines = 5;
|
||||
warningMessage = malloc(sizeof(char) * 256);
|
||||
warningMessage = calloc(256, sizeof(char));
|
||||
sprintf(warningMessage, sWarningSocket, configHostPort);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ static struct DjuiPopupList* sPopupListHead = NULL;
|
|||
static f32 sPopupListY = 0;
|
||||
|
||||
static void djui_popup_add_to_list(struct DjuiPopup* popup) {
|
||||
struct DjuiPopupList* node = malloc(sizeof(struct DjuiPopupList));
|
||||
struct DjuiPopupList* node = calloc(1, sizeof(struct DjuiPopupList));
|
||||
node->popup = popup;
|
||||
node->createTime = clock_elapsed();
|
||||
node->next = sPopupListHead;
|
||||
|
@ -34,7 +34,7 @@ static void djui_popup_destroy(struct DjuiBase* base) {
|
|||
}
|
||||
|
||||
struct DjuiPopup* djui_popup_create(const char* message, int lines) {
|
||||
struct DjuiPopup* popup = malloc(sizeof(struct DjuiPopup));
|
||||
struct DjuiPopup* popup = calloc(1, sizeof(struct DjuiPopup));
|
||||
struct DjuiBase* base = &popup->base;
|
||||
|
||||
f32 height = lines * 32 + 32;
|
||||
|
|
|
@ -33,7 +33,7 @@ static void djui_rect_destroy(struct DjuiBase* base) {
|
|||
}
|
||||
|
||||
struct DjuiRect* djui_rect_create(struct DjuiBase* parent) {
|
||||
struct DjuiRect* rect = malloc(sizeof(struct DjuiRect));
|
||||
struct DjuiRect* rect = calloc(1, sizeof(struct DjuiRect));
|
||||
struct DjuiBase* base = &rect->base;
|
||||
|
||||
djui_base_init(parent, base, djui_rect_render, djui_rect_destroy);
|
||||
|
|
|
@ -23,7 +23,7 @@ static void djui_root_destroy(struct DjuiBase* base) {
|
|||
}
|
||||
|
||||
struct DjuiRoot* djui_root_create(void) {
|
||||
struct DjuiRoot* root = malloc(sizeof(struct DjuiRoot));
|
||||
struct DjuiRoot* root = calloc(1, sizeof(struct DjuiRoot));
|
||||
struct DjuiBase* base = &root->base;
|
||||
|
||||
djui_base_init(NULL, base, djui_root_render, djui_root_destroy);
|
||||
|
|
|
@ -73,15 +73,14 @@ static void djui_selectionbox_destroy(struct DjuiBase* base) {
|
|||
}
|
||||
|
||||
struct DjuiSelectionbox* djui_selectionbox_create(struct DjuiBase* parent, const char* message, char* choices[], u8 choiceCount, unsigned int* value) {
|
||||
struct DjuiSelectionbox* selectionbox = malloc(sizeof(struct DjuiSelectionbox));
|
||||
struct DjuiBase* base = &selectionbox->base;
|
||||
struct DjuiSelectionbox* selectionbox = calloc(1, sizeof(struct DjuiSelectionbox));
|
||||
struct DjuiBase* base = &selectionbox->base;
|
||||
|
||||
selectionbox->value = value;
|
||||
selectionbox->choices = malloc(sizeof(char*) * choiceCount);
|
||||
selectionbox->choices = calloc(choiceCount, sizeof(char*));
|
||||
for (int i = 0; i < choiceCount; i++) {
|
||||
u32 length = strlen(choices[i]);
|
||||
selectionbox->choices[i] = malloc(sizeof(char) * (length + 1));
|
||||
memset(selectionbox->choices[i], 0, sizeof(char) * (length + 1));
|
||||
selectionbox->choices[i] = calloc((length + 1), sizeof(char));
|
||||
sprintf(selectionbox->choices[i], "%s", choices[i]);
|
||||
}
|
||||
selectionbox->choiceCount = choiceCount;
|
||||
|
|
|
@ -114,7 +114,7 @@ static void djui_slider_destroy(struct DjuiBase* base) {
|
|||
}
|
||||
|
||||
struct DjuiSlider* djui_slider_create(struct DjuiBase* parent, const char* message, unsigned int* value, unsigned int min, unsigned int max) {
|
||||
struct DjuiSlider* slider = malloc(sizeof(struct DjuiSlider));
|
||||
struct DjuiSlider* slider = calloc(1, sizeof(struct DjuiSlider));
|
||||
struct DjuiBase* base = &slider->base;
|
||||
|
||||
slider->value = value;
|
||||
|
|
|
@ -19,7 +19,7 @@ void djui_text_set_text(struct DjuiText* text, const char* message) {
|
|||
|
||||
// allocate and set new message
|
||||
u16 messageLen = strlen(message);
|
||||
text->message = malloc(sizeof(char) * (messageLen + 1));
|
||||
text->message = calloc((messageLen + 1), sizeof(char));
|
||||
memcpy(text->message, message, sizeof(char) * (messageLen + 1));
|
||||
}
|
||||
|
||||
|
@ -380,7 +380,7 @@ static void djui_text_destroy(struct DjuiBase* base) {
|
|||
}
|
||||
|
||||
struct DjuiText* djui_text_create(struct DjuiBase* parent, const char* message) {
|
||||
struct DjuiText* text = malloc(sizeof(struct DjuiText));
|
||||
struct DjuiText* text = calloc(1, sizeof(struct DjuiText));
|
||||
struct DjuiBase* base = &text->base;
|
||||
|
||||
djui_base_init(parent, base, djui_text_render, djui_text_destroy);
|
||||
|
|
|
@ -142,7 +142,7 @@ static void djui_three_panel_destroy(struct DjuiBase* base) {
|
|||
}
|
||||
|
||||
struct DjuiThreePanel* djui_three_panel_create(struct DjuiBase* parent, f32 minHeaderSize, f32 bodySize, f32 minFooterSize) {
|
||||
struct DjuiThreePanel* threePanel = malloc(sizeof(struct DjuiThreePanel));
|
||||
struct DjuiThreePanel* threePanel = calloc(1, sizeof(struct DjuiThreePanel));
|
||||
struct DjuiBase* base = &threePanel->base;
|
||||
|
||||
djui_base_init(parent, base, djui_three_panel_render, djui_three_panel_destroy);
|
||||
|
|
Loading…
Reference in New Issue