Revision: 7441
Author: nogu.dev
Date: Sat Feb 11 02:10:19 2012
Log: * xim/helper.cpp
- (send_im_list): Check return value of asprintf.
GLIBC version of asprintf doesn't set the 1st arguments to NULL
even on failure. Note that free(NULL) does nothing.
* xim/locale.cpp
- (get_valid_locales, all_locales): Ditto.
* xim/main.cpp
- (init_supported_locales): Ditto.
* xim/ximserver.cpp
- (InputContext::switch_system_global_im, InputContext::update_prop_list,
InputContext::update_prop_label): Ditto.
http://code.google.com/p/uim/source/detail?r=7441
Modified:
/trunk/xim/helper.cpp
/trunk/xim/locale.cpp
/trunk/xim/main.cpp
/trunk/xim/ximserver.cpp
=======================================
--- /trunk/xim/helper.cpp Wed Jan 11 00:17:24 2012
+++ /trunk/xim/helper.cpp Sat Feb 11 02:10:19 2012
@@ -86,9 +86,10 @@
if (strcmp(encoding, "UTF-8"))
client_locale = focusedContext->get_ic()->get_lang_region();
- asprintf(&buf, "im_list\ncharset=UTF-8\n");
- if (!buf)
- return;
+ if (asprintf(&buf, "im_list\ncharset=UTF-8\n") == -1) {
+ free(buf);
+ return;
+ }
std::list<UIMInfo>::iterator it;
for (it = uim_info.begin(); it != uim_info.end(); ++it) {
@@ -101,11 +102,12 @@
const char *language;
language = uim_get_language_name_from_locale(it->lang);
- asprintf(&tmp, "%s\t%s\t%s\t", it->name,
+ if (asprintf(&tmp, "%s\t%s\t%s\t", it->name,
language ? language : "",
- it->desc ? it->desc : "");
- if (!tmp)
- return;
+ it->desc ? it->desc : "") == -1) {
+ free(buf);
+ return;
+ }
len = static_cast<int>(strlen(buf) + strlen(tmp));
buf = (char *)realloc(buf, sizeof(char) * len + 1);
if (!buf) {
@@ -116,9 +118,10 @@
free(tmp);
if (!strcmp(it->name, current_im_name)) {
- asprintf(&tmp, "selected\n");
- if (!tmp)
- return;
+ if (asprintf(&tmp, "selected\n") == -1) {
+ free(tmp);
+ return;
+ }
len = static_cast<int>(strlen(buf) + strlen(tmp));
buf = (char *)realloc(buf, sizeof(char) * len + 1);
if (!buf) {
@@ -128,9 +131,10 @@
strcat(buf, tmp);
free(tmp);
} else {
- asprintf(&tmp, "\n");
- if (!tmp)
- return;
+ if (asprintf(&tmp, "\n") == -1) {
+ free(tmp);
+ return;
+ }
len = static_cast<int>(strlen(buf) + strlen(tmp));
buf = (char *)realloc(buf, sizeof(char) * len + 1);
if (!buf) {
=======================================
--- /trunk/xim/locale.cpp Wed Jan 11 00:17:24 2012
+++ /trunk/xim/locale.cpp Sat Feb 11 02:10:19 2012
@@ -281,7 +281,10 @@
// locales is separated with ':'
while ((locale = strsep(&tmpp, ":")) != NULL) {
if (setlocale(LC_CTYPE, locale) != NULL) {
- asprintf(&validated, "%s:", locale);
+ if (asprintf(&validated, "%s:", locale) == -1) {
+ free(validated);
+ continue;
+ }
len += static_cast<int>(strlen(validated));
if (valid_locales) {
valid_locales = (char *)realloc(valid_locales, len + 1);
@@ -308,7 +311,10 @@
strcat(test_locale, encoding);
if (setlocale(LC_CTYPE, test_locale) != NULL) {
- asprintf(&validated, "%s:", locale);
+ if (asprintf(&validated, "%s:", locale) == -1) {
+ free(validated);
+ continue;
+ }
len += static_cast<int>(strlen(validated));
if (valid_locales) {
@@ -364,7 +370,11 @@
continue;
}
- asprintf(&tmp, "%s:", valid_locales);
+ if (asprintf(&tmp, "%s:", valid_locales) == -1) {
+ free((char *)valid_locales);
+ free(tmp);
+ continue;
+ }
free((char *)valid_locales);
if (locales == NULL) {
=======================================
--- /trunk/xim/main.cpp Wed Jan 11 00:17:24 2012
+++ /trunk/xim/main.cpp Sat Feb 11 02:10:19 2012
@@ -470,7 +470,10 @@
const char *s;
int len;
- asprintf(&supported_locales, "@locale=");
+ if (asprintf(&supported_locales, "@locale=") == -1) {
+ free(supported_locales);
+ return;
+ }
len = static_cast<int>(strlen(supported_locales));
// get all locales
=======================================
--- /trunk/xim/ximserver.cpp Wed Jan 11 00:17:24 2012
+++ /trunk/xim/ximserver.cpp Sat Feb 11 02:10:19 2012
@@ -505,7 +505,10 @@
for (it = XimServer::gServerMap.begin(); it !=
XimServer::gServerMap.end(); ++it)
(*it).second->changeContext(name);
- asprintf(&msg, "im_change_whole_desktop\n%s\n", name);
+ if (asprintf(&msg, "im_change_whole_desktop\n%s\n", name) == -1) {
+ free(msg);
+ return;
+ }
uim_helper_send_message(lib_uim_fd, msg);
free(msg);
}
@@ -1143,9 +1146,10 @@
{
char *buf;
- asprintf(&buf, "prop_list_update\ncharset=UTF-8\n%s", str);
- if (!buf)
- return;
+ if (asprintf(&buf, "prop_list_update\ncharset=UTF-8\n%s", str) == -1) {
+ free(buf);
+ return;
+ }
uim_helper_send_message(lib_uim_fd, buf);
free(buf);
@@ -1187,9 +1191,10 @@
{
char *buf;
- asprintf(&buf, "prop_label_update\ncharset=UTF-8\n%s", str);
- if (!buf)
- return;
+ if (asprintf(&buf, "prop_label_update\ncharset=UTF-8\n%s", str) == -1)
{
+ free(buf);
+ return;
+ }
uim_helper_send_message(lib_uim_fd, buf);
free(buf);
#if 0