diff options
| author | 2023-05-15 10:31:15 +0200 | |
|---|---|---|
| committer | 2023-05-15 10:31:15 +0200 | |
| commit | 59b049fe3b689eac6e028a9b5537bc593b9e3696 (patch) | |
| tree | f680a7a0ba9dd2eadabf897820ccda0a6638c00a /xs_json.h | |
| parent | Merge pull request 'Reformat the codeblocks in README.md' (#35) from bouncepa... (diff) | |
| download | penes-snac2-59b049fe3b689eac6e028a9b5537bc593b9e3696.tar.gz penes-snac2-59b049fe3b689eac6e028a9b5537bc593b9e3696.tar.xz penes-snac2-59b049fe3b689eac6e028a9b5537bc593b9e3696.zip | |
Backport from xs.
Diffstat (limited to 'xs_json.h')
| -rw-r--r-- | xs_json.h | 31 |
1 files changed, 25 insertions, 6 deletions
| @@ -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); |