summaryrefslogtreecommitdiff
path: root/ext/json/utf8_to_utf16.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/json/utf8_to_utf16.c')
-rw-r--r--ext/json/utf8_to_utf16.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/ext/json/utf8_to_utf16.c b/ext/json/utf8_to_utf16.c
index 599f0e13b..508bc9368 100644
--- a/ext/json/utf8_to_utf16.c
+++ b/ext/json/utf8_to_utf16.c
@@ -30,7 +30,7 @@ SOFTWARE.
#include "utf8_decode.h"
int
-utf8_to_utf16(unsigned short w[], char p[], int length)
+utf8_to_utf16(unsigned short *w, char p[], int length)
{
int c;
int the_index = 0;
@@ -43,14 +43,17 @@ utf8_to_utf16(unsigned short w[], char p[], int length)
return (c == UTF8_END) ? the_index : UTF8_ERROR;
}
if (c < 0x10000) {
- w[the_index] = (unsigned short)c;
+ if (w) {
+ w[the_index] = (unsigned short)c;
+ }
the_index += 1;
} else {
c -= 0x10000;
- w[the_index] = (unsigned short)(0xD800 | (c >> 10));
- the_index += 1;
- w[the_index] = (unsigned short)(0xDC00 | (c & 0x3FF));
- the_index += 1;
+ if (w) {
+ w[the_index] = (unsigned short)(0xD800 | (c >> 10));
+ w[the_index + 1] = (unsigned short)(0xDC00 | (c & 0x3FF));
+ }
+ the_index += 2;
}
}
}