MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

add handling for invalid indices in string methods

+5 -3
+5 -3
src/ant.c
··· 18311 18311 if (vtype(str) != T_STR) return js_mkerr(js, "charCodeAt called on non-string"); 18312 18312 18313 18313 double idx_d = nargs < 1 ? 0.0 : js_to_number(js, args[0]); 18314 - if (isnan(idx_d) || isinf(idx_d)) return tov(JS_NAN); 18314 + if (isnan(idx_d)) idx_d = 0.0; 18315 + if (isinf(idx_d) || idx_d > (double)LONG_MAX) return tov(JS_NAN); 18315 18316 18316 18317 long idx_l = (long) idx_d; 18317 18318 if (idx_l < 0) return tov(JS_NAN); ··· 18332 18333 if (vtype(str) != T_STR) return js_mkerr(js, "codePointAt called on non-string"); 18333 18334 18334 18335 double idx_d = nargs < 1 ? 0.0 : js_to_number(js, args[0]); 18335 - if (isnan(idx_d) || isinf(idx_d)) return js_mkundef(); 18336 + if (isnan(idx_d)) idx_d = 0.0; 18337 + if (isinf(idx_d) || idx_d > (double)LONG_MAX) return js_mkundef(); 18336 18338 18337 18339 long idx_l = (long) idx_d; 18338 18340 if (idx_l < 0) return js_mkundef(); ··· 18564 18566 if (isnan(idx_d)) idx_d = 0; 18565 18567 else if (idx_d < 0) idx_d = -floor(-idx_d); 18566 18568 else idx_d = floor(idx_d); 18567 - if (idx_d < 0) return js_mkstr(js, "", 0); 18569 + if (idx_d < 0 || isinf(idx_d)) return js_mkstr(js, "", 0); 18568 18570 18569 18571 jsoff_t idx = (jsoff_t) idx_d; 18570 18572 jsoff_t str_len = offtolen(loadoff(js, (jsoff_t) vdata(str)));