Skip to content

Commit

Permalink
Stop using dynamic allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
Crayon2000 committed Nov 10, 2024
1 parent 9538834 commit 5850eb3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ pkg_check_modules(JANSSON REQUIRED jansson)
include(FetchContent)
FetchContent_Declare(
inih
GIT_REPOSITORY https://github.com/benhoyt/inih.git
GIT_TAG r58
URL https://github.com/benhoyt/inih/archive/refs/tags/r58.tar.gz
)
FetchContent_MakeAvailable(inih)

Expand Down
14 changes: 7 additions & 7 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ typedef struct {

/**
* Handler for ini parser.
* @param user User data.
* @param section Section name.
* @param name Name.
* @param value Value.
* @return Returns nonzero on success, zero on error.
*/
static int handler(void* user, const char* section, const char* name, const char* value)
Expand Down Expand Up @@ -113,7 +117,7 @@ int main(int argc, char **argv)
VPADReadError error;
VPADStatus vpad_data;

char * IP_str = (char*)malloc(32);
char IP_str[32];
int8_t selected_digit = 0;

// Read default settings from file
Expand Down Expand Up @@ -192,7 +196,6 @@ int main(int argc, char **argv)

running = WHBProcIsRunning();
}
free(IP_str);
if(running == false) {
WHBUnmountSdCard();
ConsoleFree();
Expand All @@ -218,15 +221,15 @@ int main(int argc, char **argv)
ResetOrientation();

// Get IP Address (without spaces)
char * IP_ADDRESS = (char*)malloc(32);
char IP_ADDRESS[32];
snprintf(IP_ADDRESS, 32, "%d.%d.%d.%d", IP[0], IP[1], IP[2], IP[3]);

// Initialize the UDP connection
udp_init(IP_ADDRESS, Port);

if(ConsoleDrawStart() == true) {
// Output the IP address
char * msg_connected = (char*)malloc(255);
char msg_connected[255];
snprintf(msg_connected, 255, "Connected to %s:%d", IP_ADDRESS, Port);

// Print to TV
Expand All @@ -246,8 +249,6 @@ int main(int argc, char **argv)
OSScreenPutFontEx(SCREEN_DRC, 0, 16, "Hold the HOME button to exit.");

ConsoleDrawEnd();

free(msg_connected);
}

// Save settings to file
Expand Down Expand Up @@ -358,7 +359,6 @@ int main(int argc, char **argv)
}
}

free(IP_ADDRESS);
VPADShutdown();
KPADShutdown();
HPADShutdown();
Expand Down

0 comments on commit 5850eb3

Please sign in to comment.