[gnome-color-manager] Allow writing dictionary items of longer then 512 bytes
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Allow writing dictionary items of longer then 512 bytes
- Date: Wed, 29 Jun 2011 08:15:13 +0000 (UTC)
commit 1aa39aab3bed617c0afa4a313ea379e8bbba4473
Author: Richard Hughes <richard hughsie com>
Date: Wed Jun 29 09:14:59 2011 +0100
Allow writing dictionary items of longer then 512 bytes
src/gcm-calibrate-main.c | 39 ++++++++++++++++++++++++++++++++++-----
1 files changed, 34 insertions(+), 5 deletions(-)
---
diff --git a/src/gcm-calibrate-main.c b/src/gcm-calibrate-main.c
index 78359c3..59e7975 100644
--- a/src/gcm-calibrate-main.c
+++ b/src/gcm-calibrate-main.c
@@ -311,17 +311,46 @@ gcm_calib_get_vbox_for_page (GcmCalibratePriv *calib,
return NULL;
}
+static wchar_t *
+utf8_to_wchar_t (const char *src)
+{
+ gsize len;
+ gsize converted;
+ wchar_t *buf = NULL;
+
+ len = mbstowcs (NULL, src, 0);
+ if (len == (gsize) -1) {
+ g_warning ("Invalid UTF-8 in string %s", src);
+ goto out;
+ }
+ len += 1;
+ buf = g_malloc (sizeof (wchar_t) * len);
+ converted = mbstowcs (buf, src, len - 1);
+ g_assert (converted != (gsize) -1);
+ buf[converted] = '\0';
+out:
+ return buf;
+}
+
static cmsBool
_cmsDictAddEntryAscii (cmsHANDLE dict,
const gchar *key,
const gchar *value)
{
- cmsBool ret;
- wchar_t mb_key[1024];
- wchar_t mb_value[1024];
- mbstowcs (mb_key, key, sizeof (mb_key));
- mbstowcs (mb_value, value, sizeof (mb_value));
+ cmsBool ret = FALSE;
+ wchar_t *mb_key = NULL;
+ wchar_t *mb_value = NULL;
+
+ mb_key = utf8_to_wchar_t (key);
+ if (mb_key == NULL)
+ goto out;
+ mb_value = utf8_to_wchar_t (value);
+ if (mb_value == NULL)
+ goto out;
ret = cmsDictAddEntry (dict, mb_key, mb_value, NULL, NULL);
+out:
+ g_free (mb_key);
+ g_free (mb_value);
return ret;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]