[PATCH 2/4] Allocate memory for and truncate strings that go into the title bar

Lubomir I. Ivanov neolit123 at gmail.com
Thu Oct 18 03:21:37 PDT 2012


On 18 October 2012 12:11, Martin Gysel <me at bearsh.org> wrote:
> Am 17.10.2012 23:47, schrieb Lubomir I. Ivanov:
>> could have been prettier if glib had something in the lines of
>> g_utf8_snprintf().
>> i'd be interested in improvements or alternatives. i can think of one
>> but this is actually safer.
>
> what's wrong with:
>
> char* title:
> basename = g_path_get_basename(existing_filename);
> title = g_strdup_printf("Subsurface: %s", basename);
> gtk_window_set_title(GTK_WINDOW(main_window), title);
> free(basename);
> free(title);
>

this is cleaner for that particular hunk.

> does it matter if any of these strings are utf8 or not? at the end they
> are just a null-terminated char buffer and you are not relying on a
> particular string (not char buffer) length in that very use case
>

in this case no as we aren't truncating basename (the max size of
which is OS specific).
but if we decide to do that, g_utf8_strlen() + g_utf8_strncpy() are
the only usable functions i see on gnome's website.

you can send a patch with your mods if you want.

lubomir
--


More information about the subsurface mailing list