Skip to content

Commit

Permalink
Update memory allocation usage/checks
Browse files Browse the repository at this point in the history
  • Loading branch information
gerbert committed Dec 25, 2022
1 parent 417d7e6 commit 1ad4064
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ static char *get_input(t_mode mode, size_t sz) {
return NULL;

char *buffer = (char *) malloc(sizeof(char) * sz);
if (buffer == NULL)
if (buffer == NULL) {
printf("Memory allocation error");
return NULL;
}

memset(buffer, 0, sizeof(char) * sz);
char *ptr = &buffer[0];
Expand Down Expand Up @@ -62,6 +64,7 @@ static char *get_input(t_mode mode, size_t sz) {
while ((key = os_GetKey()) != k_Enter) {
if (key == k_Quit) {
os_DisableCursor();
free(buffer);
return NULL;
} else if (key == k_Clear) {
os_ClrLCD();
Expand Down Expand Up @@ -125,10 +128,8 @@ void convert(void *value) {

ptr = get_input(mode, sz);
os_SetCursorPos(1, 0);
if (ptr == NULL) {
printf("Failed to convert a value");
if (ptr == NULL)
return;
}

switch (mode) {
case MODE_DEC_HEX ... MODE_DEC_BIN:
Expand Down

0 comments on commit 1ad4064

Please sign in to comment.