summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-05-15 10:31:15 +0200
committerGravatar default2023-05-15 10:31:15 +0200
commit59b049fe3b689eac6e028a9b5537bc593b9e3696 (patch)
treef680a7a0ba9dd2eadabf897820ccda0a6638c00a
parentMerge pull request 'Reformat the codeblocks in README.md' (#35) from bouncepa... (diff)
downloadsnac2-59b049fe3b689eac6e028a9b5537bc593b9e3696.tar.gz
snac2-59b049fe3b689eac6e028a9b5537bc593b9e3696.tar.xz
snac2-59b049fe3b689eac6e028a9b5537bc593b9e3696.zip
Backport from xs.
-rw-r--r--xs_json.h31
-rw-r--r--xs_version.h2
2 files changed, 26 insertions, 7 deletions
diff --git a/xs_json.h b/xs_json.h
index 6af47a2..c28f5d5 100644
--- a/xs_json.h
+++ b/xs_json.h
@@ -238,20 +238,39 @@ static xs_val *_xs_json_loads_lexer(const char **json, js_type *t)
238 case 't': c = '\t'; break; 238 case 't': c = '\t'; break;
239 case 'u': /* Unicode codepoint as an hex char */ 239 case 'u': /* Unicode codepoint as an hex char */
240 s++; 240 s++;
241 memcpy(tmp, s, 4); 241 strncpy(tmp, s, 4);
242 s += 3;
243 tmp[4] = '\0'; 242 tmp[4] = '\0';
244 243
244 if (strlen(tmp) != 4) {
245 *t = JS_ERROR;
246 break;
247 }
248
249 s += 3; /* skip as it was one byte */
250
245 sscanf(tmp, "%04x", &i); 251 sscanf(tmp, "%04x", &i);
246 252
247 if (i >= 0xd800 && i <= 0xdfff) { 253 if (i >= 0xd800 && i <= 0xdfff) {
248 /* it's a surrogate pair */ 254 /* it's a surrogate pair */
249 cp = (i & 0x3ff) << 10; 255 cp = (i & 0x3ff) << 10;
250 256
251 /* skip to the next value */ 257 /* skip to the next value (last char + \ + u) */
252 s += 3; 258 s++;
253 memcpy(tmp, s, 4); 259 if (memcmp(s, "\\u", 2) != 0) {
254 s += 3; 260 *t = JS_ERROR;
261 break;
262 }
263 s += 2;
264
265 strncpy(tmp, s, 4);
266 tmp[4] = '\0';
267
268 if (strlen(tmp) != 4) {
269 *t = JS_ERROR;
270 break;
271 }
272
273 s += 3; /* skip as it was one byte */
255 274
256 sscanf(tmp, "%04x", &i); 275 sscanf(tmp, "%04x", &i);
257 cp |= (i & 0x3ff); 276 cp |= (i & 0x3ff);
diff --git a/xs_version.h b/xs_version.h
index 4c842e3..fce4f34 100644
--- a/xs_version.h
+++ b/xs_version.h
@@ -1 +1 @@
/* 333e84c76cd0e51f9f98a36df2eb3bf81e0d2608 */ /* 494e346f92431041350f72431417eee03a23eafd */