diff --git a/programs/include/gui/terminal.hpp b/programs/include/gui/terminal.hpp index 5e008e2..29300d4 100644 --- a/programs/include/gui/terminal.hpp +++ b/programs/include/gui/terminal.hpp @@ -562,8 +562,8 @@ static inline void terminal_resize(TerminalState* t, int new_cols, int new_rows) } } - if (t->cells) montauk::mfree(t->cells); - if (t->alt_cells) montauk::mfree(t->alt_cells); + if (t->cells) montauk::free(t->cells); + if (t->alt_cells) montauk::free(t->alt_cells); t->cells = new_cells; t->alt_cells = new_alt; diff --git a/programs/src/desktop/app_klog.cpp b/programs/src/desktop/app_klog.cpp index 045b980..4c21037 100644 --- a/programs/src/desktop/app_klog.cpp +++ b/programs/src/desktop/app_klog.cpp @@ -101,8 +101,8 @@ static void klog_on_poll(Window* win) { static void klog_on_close(Window* win) { KlogState* klog = (KlogState*)win->app_data; if (klog) { - if (klog->term.cells) montauk::mfree(klog->term.cells); - if (klog->term.alt_cells) montauk::mfree(klog->term.alt_cells); + if (klog->term.cells) montauk::free(klog->term.cells); + if (klog->term.alt_cells) montauk::free(klog->term.alt_cells); if (klog->klog_buf) montauk::mfree(klog->klog_buf); montauk::mfree(klog); win->app_data = nullptr; diff --git a/programs/src/desktop/app_terminal.cpp b/programs/src/desktop/app_terminal.cpp index 6adf805..6c6e525 100644 --- a/programs/src/desktop/app_terminal.cpp +++ b/programs/src/desktop/app_terminal.cpp @@ -39,7 +39,8 @@ static void terminal_on_key(Window* win, const Montauk::KeyEvent& key) { static void terminal_on_close(Window* win) { TerminalState* ts = (TerminalState*)win->app_data; if (ts) { - if (ts->cells) montauk::mfree(ts->cells); + if (ts->cells) montauk::free(ts->cells); + if (ts->alt_cells) montauk::free(ts->alt_cells); montauk::mfree(ts); win->app_data = nullptr; } diff --git a/programs/src/desktop/main.cpp b/programs/src/desktop/main.cpp index 789c8a4..4497cc1 100644 --- a/programs/src/desktop/main.cpp +++ b/programs/src/desktop/main.cpp @@ -87,7 +87,7 @@ void gui::desktop_init(DesktopState* ds) { ds->settings.ui_scale = 1; // Try to load default wallpaper - wallpaper_load(&ds->settings, "0:/home/gustav-gullstrand-d6kSvT2xZQo-unsplash.jpg", + wallpaper_load(&ds->settings, "0:/home/stephen-walker-DaC8D3USffk-unsplash.jpg", ds->screen_w, ds->screen_h); montauk::win_setscale(1); diff --git a/programs/src/wikipedia/main.cpp b/programs/src/wikipedia/main.cpp index ad4f098..8608de5 100644 --- a/programs/src/wikipedia/main.cpp +++ b/programs/src/wikipedia/main.cpp @@ -283,7 +283,8 @@ static void add_empty_line() { // Word-wrap a text segment into display lines using pixel-width measurement. static void wrap_text(TrueTypeFont* font, int size, const char* text, int textLen, int max_px, Color color) { - char cur[256]; + static constexpr int MAX_LINE = 255; + char cur[MAX_LINE + 1]; int cur_len = 0; const char* p = text; const char* end = text + textLen; @@ -298,14 +299,16 @@ static void wrap_text(TrueTypeFont* font, int size, const char* text, int textLe if (word_len <= 0) continue; // Build candidate: current line + space + word - char test[260]; + char test[MAX_LINE + 1]; int test_len = cur_len; memcpy(test, cur, cur_len); - if (cur_len > 0) test[test_len++] = ' '; - int copy = word_len < (int)(sizeof(test) - test_len - 1) - ? word_len : (int)(sizeof(test) - test_len - 1); - memcpy(test + test_len, word_start, copy); - test_len += copy; + if (cur_len > 0 && test_len < MAX_LINE) test[test_len++] = ' '; + int avail = MAX_LINE - test_len; + int copy = word_len < avail ? word_len : avail; + if (copy > 0) { + memcpy(test + test_len, word_start, copy); + test_len += copy; + } test[test_len] = '\0'; int test_w = font->measure_text(test, size); @@ -316,7 +319,7 @@ static void wrap_text(TrueTypeFont* font, int size, const char* text, int textLe } else { // Emit current line and start fresh if (cur_len > 0) add_line(cur, cur_len, color, size, font); - int wl = word_len < 254 ? word_len : 254; + int wl = word_len < MAX_LINE ? word_len : MAX_LINE; memcpy(cur, word_start, wl); cur_len = wl; cur[cur_len] = '\0';