summaryrefslogtreecommitdiff
path: root/eglib
diff options
context:
space:
mode:
authorJo Shields <directhex@apebox.org>2013-10-17 13:55:48 +0100
committerJo Shields <directhex@apebox.org>2013-10-17 13:55:48 +0100
commitd0a215f5626219ff7927f576588a777e5331c7be (patch)
tree000e730e32af8a6528a38a4164fef173d4b7fa2a /eglib
parent621d62beabd2b7a9cf0a7d77b961695f9ebfaac5 (diff)
downloadmono-d0a215f5626219ff7927f576588a777e5331c7be.tar.gz
Imported Upstream version 3.2.3+dfsgupstream/3.2.3+dfsg
Diffstat (limited to 'eglib')
-rw-r--r--eglib/src/gfile-posix.c2
-rw-r--r--eglib/src/gfile-win32.c1
-rw-r--r--eglib/src/giconv.c86
-rw-r--r--eglib/src/gmodule-win32.c1
-rw-r--r--eglib/src/gstring.c3
5 files changed, 62 insertions, 31 deletions
diff --git a/eglib/src/gfile-posix.c b/eglib/src/gfile-posix.c
index d52ad94880..49ee58a142 100644
--- a/eglib/src/gfile-posix.c
+++ b/eglib/src/gfile-posix.c
@@ -156,7 +156,7 @@ g_get_current_dir (void)
{
#ifdef __native_client__
char *buffer;
- if ((buffer = getenv("NACL_PWD"))) {
+ if ((buffer = g_getenv("NACL_PWD"))) {
buffer = g_strdup(buffer);
} else {
buffer = g_strdup(".");
diff --git a/eglib/src/gfile-win32.c b/eglib/src/gfile-win32.c
index 6a4bbefb1d..a2e41ea9f6 100644
--- a/eglib/src/gfile-win32.c
+++ b/eglib/src/gfile-win32.c
@@ -61,6 +61,7 @@ int mkstemp (char *tmp_template)
fd = _wopen( utf16_template, _O_BINARY | _O_CREAT /*| _O_TEMPORARY*/ | _O_EXCL, _S_IREAD | _S_IWRITE);
}
+ /* FIXME: this will crash if utf16_template == NULL */
sprintf (tmp_template + strlen (tmp_template) - 6, "%S", utf16_template + wcslen (utf16_template) - 6);
g_free (utf16_template);
diff --git a/eglib/src/giconv.c b/eglib/src/giconv.c
index 9fe0edd332..61db988909 100644
--- a/eglib/src/giconv.c
+++ b/eglib/src/giconv.c
@@ -174,14 +174,34 @@ gsize
g_iconv (GIConv cd, gchar **inbytes, gsize *inbytesleft,
gchar **outbytes, gsize *outbytesleft)
{
- size_t inleft, outleft;
+ gsize inleft, outleft;
char *inptr, *outptr;
gunichar c;
int rc = 0;
#ifdef HAVE_ICONV
- if (cd->cd != (iconv_t) -1)
- return iconv (cd->cd, inbytes, inbytesleft, outbytes, outbytesleft);
+ if (cd->cd != (iconv_t) -1) {
+ /* Note: gsize may have a different size than size_t, so we need to
+ remap inbytesleft and outbytesleft to size_t's. */
+ size_t *outleftptr, *inleftptr;
+ size_t n_outleft, n_inleft;
+
+ if (inbytesleft) {
+ n_inleft = *inbytesleft;
+ inleftptr = &n_inleft;
+ } else {
+ inleftptr = NULL;
+ }
+
+ if (outbytesleft) {
+ n_outleft = *outbytesleft;
+ outleftptr = &n_outleft;
+ } else {
+ outleftptr = NULL;
+ }
+
+ return iconv (cd->cd, inbytes, inleftptr, outbytes, outleftptr);
+ }
#endif
if (outbytes == NULL || outbytesleft == NULL) {
@@ -640,7 +660,7 @@ gchar *
g_convert (const gchar *str, gssize len, const gchar *to_charset, const gchar *from_charset,
gsize *bytes_read, gsize *bytes_written, GError **err)
{
- size_t outsize, outused, outleft, inleft, grow, rc;
+ gsize outsize, outused, outleft, inleft, grow, rc;
char *result, *outbuf, *inbuf;
gboolean flush = FALSE;
gboolean done = FALSE;
@@ -676,7 +696,7 @@ g_convert (const gchar *str, gssize len, const gchar *to_charset, const gchar *f
else
rc = g_iconv (cd, NULL, NULL, &outbuf, &outleft);
- if (rc == (size_t) -1) {
+ if (rc == (gsize) -1) {
switch (errno) {
case E2BIG:
/* grow our result buffer */
@@ -901,7 +921,7 @@ eg_utf8_to_utf16_general (const gchar *str, glong len, glong *items_read, glong
size_t inleft;
char *inptr;
gunichar c;
- int n;
+ int u, n;
g_return_val_if_fail (str != NULL, NULL);
@@ -910,6 +930,7 @@ eg_utf8_to_utf16_general (const gchar *str, glong len, glong *items_read, glong
g_set_error (err, G_CONVERT_ERROR, G_CONVERT_ERROR_FAILED, "Conversions with embedded nulls must pass the string length");
return NULL;
}
+
len = strlen (str);
}
@@ -917,29 +938,18 @@ eg_utf8_to_utf16_general (const gchar *str, glong len, glong *items_read, glong
inleft = len;
while (inleft > 0) {
- if ((n = decode_utf8 (inptr, inleft, &c)) < 0) {
- if (errno == EILSEQ) {
- g_set_error (err, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
- "Illegal byte sequence encounted in the input.");
- } else if (items_read) {
- /* partial input is ok if we can let our caller know... */
- break;
- } else {
- g_set_error (err, G_CONVERT_ERROR, G_CONVERT_ERROR_PARTIAL_INPUT,
- "Partial byte sequence encountered in the input.");
- }
-
- if (items_read)
- *items_read = inptr - str;
-
- if (items_written)
- *items_written = 0;
-
- return NULL;
- } else if (c == 0 && !include_nuls)
+ if ((n = decode_utf8 (inptr, inleft, &c)) < 0)
+ goto error;
+
+ if (c == 0 && !include_nuls)
break;
- outlen += g_unichar_to_utf16 (c, NULL);
+ if ((u = g_unichar_to_utf16 (c, NULL)) < 0) {
+ errno = EILSEQ;
+ goto error;
+ }
+
+ outlen += u;
inleft -= n;
inptr += n;
}
@@ -957,7 +967,8 @@ eg_utf8_to_utf16_general (const gchar *str, glong len, glong *items_read, glong
while (inleft > 0) {
if ((n = decode_utf8 (inptr, inleft, &c)) < 0)
break;
- else if (c == 0 && !include_nuls)
+
+ if (c == 0 && !include_nuls)
break;
outptr += g_unichar_to_utf16 (c, outptr);
@@ -968,6 +979,25 @@ eg_utf8_to_utf16_general (const gchar *str, glong len, glong *items_read, glong
*outptr = '\0';
return outbuf;
+
+ error:
+ if (errno == EILSEQ) {
+ g_set_error (err, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
+ "Illegal byte sequence encounted in the input.");
+ } else if (items_read) {
+ /* partial input is ok if we can let our caller know... */
+ } else {
+ g_set_error (err, G_CONVERT_ERROR, G_CONVERT_ERROR_PARTIAL_INPUT,
+ "Partial byte sequence encountered in the input.");
+ }
+
+ if (items_read)
+ *items_read = inptr - str;
+
+ if (items_written)
+ *items_written = 0;
+
+ return NULL;
}
gunichar2 *
diff --git a/eglib/src/gmodule-win32.c b/eglib/src/gmodule-win32.c
index 68d1619825..24010b5891 100644
--- a/eglib/src/gmodule-win32.c
+++ b/eglib/src/gmodule-win32.c
@@ -141,6 +141,7 @@ g_module_error (void)
TCHAR* buf = NULL;
DWORD code = GetLastError ();
+ /* FIXME: buf must not be NULL! */
FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL,
code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 0, NULL);
diff --git a/eglib/src/gstring.c b/eglib/src/gstring.c
index 9df5d73c28..ba75789bc8 100644
--- a/eglib/src/gstring.c
+++ b/eglib/src/gstring.c
@@ -235,9 +235,8 @@ g_string_truncate (GString *string, gsize len)
g_return_val_if_fail (string != NULL, string);
/* Silent return */
- if (len < 0 || len >= string->len) {
+ if (len >= string->len)
return string;
- }
string->len = len;
string->str[len] = 0;