[gjs/wip/ptomato/warnings: 9/14] byte array: Don't reinterpret char * as jschar *
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/ptomato/warnings: 9/14] byte array: Don't reinterpret char * as jschar *
- Date: Thu, 20 Oct 2016 05:49:27 +0000 (UTC)
commit e4a7219d70fc14aefe06294acec95592235275c8
Author: Philip Chimento <philip chimento gmail com>
Date: Sun Oct 2 15:18:15 2016 -0700
byte array: Don't reinterpret char * as jschar *
Doing so breaks alignment requirements and may have been the cause of an
ARM-only crash we saw on ByteArray a couple years ago.
Doing an extra copy seems wasteful, but is the recommended way according
to an article on the subject [1], and compilers are sometimes able to
optimize out the copy these days...
[1] http://blog.regehr.org/archives/959
gjs/byteArray.cpp | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/gjs/byteArray.cpp b/gjs/byteArray.cpp
index 0d8036f..baccc4c 100644
--- a/gjs/byteArray.cpp
+++ b/gjs/byteArray.cpp
@@ -453,6 +453,7 @@ to_string_func(JSContext *context,
GError *error;
JSString *s;
char *u16_str;
+ jschar *u16_out;
error = NULL;
u16_str = g_convert(data,
@@ -474,15 +475,16 @@ to_string_func(JSContext *context,
*/
g_assert((bytes_written % 2) == 0);
- s = JS_NewUCStringCopyN(context,
- (jschar*) u16_str,
- bytes_written / 2);
+ u16_out = g_new(jschar, bytes_written / 2);
+ memcpy(u16_out, u16_str, bytes_written);
+ s = JS_NewUCStringCopyN(context, u16_out, bytes_written / 2);
if (s != NULL) {
ok = true;
argv.rval().setString(s);
}
g_free(u16_str);
+ g_free(u16_out);
return ok;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]