2008-02-25 Dan Williams <dcbw@redhat.com>

* libnm-util/nm-utils.c
		- (nm_utils_ssid_to_utf8): use a dynamically allocated buffer



git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3342 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Williams 2008-02-25 22:07:40 +00:00
parent ade314556c
commit ca97fe6469
2 changed files with 24 additions and 21 deletions

View file

@ -1,3 +1,8 @@
2008-02-25 Dan Williams <dcbw@redhat.com>
* libnm-util/nm-utils.c
- (nm_utils_ssid_to_utf8): use a dynamically allocated buffer
2008-02-25 Dan Williams <dcbw@redhat.com> 2008-02-25 Dan Williams <dcbw@redhat.com>
* libnm-util/nm-setting.c * libnm-util/nm-setting.c

View file

@ -198,25 +198,23 @@ get_encodings_for_lang (const char *lang,
return success; return success;
} }
#define SSID_BUF_SIZE (IW_ESSID_MAX_SIZE + 1)
char * char *
nm_utils_ssid_to_utf8 (const char *ssid, guint32 len) nm_utils_ssid_to_utf8 (const char *ssid, guint32 len)
{ {
char * new_ssid = NULL; char *converted = NULL;
char buf[IW_ESSID_MAX_SIZE + 1]; char *buf;
guint32 buf_len = MIN (sizeof (buf) - 1, len); guint32 buf_len = MIN (SSID_BUF_SIZE - 1, len);
char * lang; char *lang;
char *e1 = NULL, *e2 = NULL, *e3 = NULL; char *e1 = NULL, *e2 = NULL, *e3 = NULL;
g_return_val_if_fail (ssid != NULL, NULL); g_return_val_if_fail (ssid != NULL, NULL);
memset (buf, 0, sizeof (buf)); buf = g_malloc0 (SSID_BUF_SIZE);
memcpy (buf, ssid, buf_len); memcpy (buf, ssid, buf_len);
if (g_utf8_validate (buf, buf_len, NULL)) { if (g_utf8_validate (buf, buf_len, NULL))
new_ssid = g_strdup (buf); return buf;
goto out;
}
/* Even if the local encoding is UTF-8, LANG may give /* Even if the local encoding is UTF-8, LANG may give
* us a clue as to what encoding SSIDs are more likely to be in. * us a clue as to what encoding SSIDs are more likely to be in.
@ -233,20 +231,20 @@ nm_utils_ssid_to_utf8 (const char *ssid, guint32 len)
g_free (lang); g_free (lang);
} }
new_ssid = g_convert (buf, buf_len, "UTF-8", e1, NULL, NULL, NULL); converted = g_convert (buf, buf_len, "UTF-8", e1, NULL, NULL, NULL);
if (!new_ssid && e2) { if (!converted && e2)
new_ssid = g_convert (buf, buf_len, "UTF-8", e2, NULL, NULL, NULL); converted = g_convert (buf, buf_len, "UTF-8", e2, NULL, NULL, NULL);
}
if (!new_ssid && e3) { if (!converted && e3)
new_ssid = g_convert (buf, buf_len, "UTF-8", e3, NULL, NULL, NULL); converted = g_convert (buf, buf_len, "UTF-8", e3, NULL, NULL, NULL);
}
if (!new_ssid) { if (!converted) {
new_ssid = g_convert_with_fallback (buf, buf_len, "UTF-8", e1, converted = g_convert_with_fallback (buf, buf_len, "UTF-8", e1,
"?", NULL, NULL, NULL); "?", NULL, NULL, NULL);
} }
out: g_free (buf);
return new_ssid; return converted;
} }
/* Shamelessly ripped from the Linux kernel ieee80211 stack */ /* Shamelessly ripped from the Linux kernel ieee80211 stack */