diff --git a/src/renderer.cpp b/src/renderer.cpp index ba8d138..755671b 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -377,16 +377,18 @@ void render_body_list_ui(SimulationState* sim, RenderState* render_state) { Rectangle panel_bounds = { (float)panel_x, (float)panel_y, (float)panel_width, (float)panel_height }; // Create body list string for raygui (NULL-terminated) - char* body_list_text = (char*)malloc(sim->body_count * 64); // 64 chars per name max + int buffer_size = sim->body_count * (64 + 1) + 1; + char* body_list_text = (char*)malloc(buffer_size); if (!body_list_text) return; - body_list_text[0] = '\0'; // Initialize empty string + body_list_text[0] = '\0'; + int offset = 0; for (int i = 0; i < sim->body_count; i++) { if (i > 0) { - strcat(body_list_text, ";"); // Separator for raygui + offset += snprintf(body_list_text + offset, buffer_size - offset, ";"); } - strcat(body_list_text, sim->bodies[i].name); + offset += snprintf(body_list_text + offset, buffer_size - offset, "%s", sim->bodies[i].name); } // Draw window