Commit 20ac70e7 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

use g_strndup() instead of g_strdup() if a length was passed.

2004-11-22  Michael Natterer  <mitch@gimp.org>

	* libgimpbase/gimputils.c (gimp_any_to_utf8): use g_strndup()
	instead of g_strdup() if a length was passed.

	* app/dialogs/info-window.c: g_strndup() the comment parasite's
	data and pass -1 as length to gimp_any_to_utf8() so we don't
	encounter the questionable (buggy?) behavior of g_utf8_validate()
	to fail upon finding '\0' within the "length" passed.
	Fixes bug #159051.
parent 88b3cb7d
2004-11-22 Michael Natterer <mitch@gimp.org>
* libgimpbase/gimputils.c (gimp_any_to_utf8): use g_strndup()
instead of g_strdup() if a length was passed.
* app/dialogs/info-window.c: g_strndup() the comment parasite's
data and pass -1 as length to gimp_any_to_utf8() so we don't
encounter the questionable (buggy?) behavior of g_utf8_validate()
to fail upon finding '\0' within the "length" passed.
Fixes bug #159051.
2004-11-22 Michael Natterer <mitch@gimp.org>
 
* plug-ins/common/struc.c: applied patch from Wolfgang Hofer
......
......@@ -220,6 +220,7 @@ info_window_create_comment (InfoDialog *info_win,
GtkWidget *vbox;
GtkWidget *vbox2;
GimpParasite *comment;
gchar *utf8;
vbox = gtk_vbox_new (FALSE, 12);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
......@@ -234,11 +235,22 @@ info_window_create_comment (InfoDialog *info_win,
/* image comment */
comment = gimp_image_parasite_find (gdisp->gimage, "gimp-comment");
if (comment == NULL)
g_snprintf (iwd->comment_str, MAX_BUF, "%s", _("(none)"));
if (comment)
{
gchar *str = g_strndup (gimp_parasite_data (comment),
gimp_parasite_data_size (comment));
utf8 = gimp_any_to_utf8 (str, -1, NULL);
}
else
g_snprintf (iwd->comment_str, MAX_BUF, "%s",
gimp_any_to_utf8 (comment->data, comment->size, NULL));
{
utf8 = g_strdup (_("(none)"));
}
g_snprintf (iwd->comment_str, MAX_BUF, "%s", utf8);
g_free (utf8);
label = gtk_label_new (iwd->comment_str);
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
......@@ -606,13 +618,25 @@ info_window_update (GimpDisplay *gdisp)
/* image comment */
{
GimpParasite *comment;
gchar *utf8;
comment = gimp_image_parasite_find (gdisp->gimage, "gimp-comment");
if (comment == NULL)
g_snprintf (iwd->comment_str, MAX_BUF, "%s", _("(none)"));
if (comment)
{
gchar *str = g_strndup (gimp_parasite_data (comment),
gimp_parasite_data_size (comment));
utf8 = gimp_any_to_utf8 (str, -1, NULL);
}
else
g_snprintf (iwd->comment_str, MAX_BUF, "%s",
gimp_any_to_utf8 (comment->data, comment->size, NULL));
{
utf8 = g_strdup (_("(none)"));
}
g_snprintf (iwd->comment_str, MAX_BUF, "%s", utf8);
g_free (utf8);
}
{
......
......@@ -136,9 +136,16 @@ gimp_any_to_utf8 (const gchar *str,
g_return_val_if_fail (str != NULL, NULL);
if (g_utf8_validate (str, len, &start_invalid))
utf8 = g_strdup (str);
{
if (len < 0)
utf8 = g_strdup (str);
else
utf8 = g_strndup (str, len);
}
else
utf8 = g_locale_to_utf8 (str, len, NULL, NULL, NULL);
{
utf8 = g_locale_to_utf8 (str, len, NULL, NULL, NULL);
}
if (! utf8)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment