Skip to content
Myr

Fix string multiplication by 0 (and less than 1) to emit empty string

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by itchyny · committed by Nico Williams · parent 88b4577 · Browse files · 2 files+10 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+10 added−4 removed

  • tests:+5 added−1 removed
  • other:+5 added−3 removed

2 files+10 added−4 removed

modified:src/builtin.c+5 added-3 removed
357 unmodified lines
358 if (ak == JV_KIND_NUMBER) {359 str = b;360 num = a;361 }362 jv res = jv_null();362 jv res;363 double d = jv_number_value(num);364 int n = 0.0 < d && d < 1.0 ? 1 : d;365 if (n > 0) {364 if (d < 0 || isnan(d)) {365 res = jv_null();366 } else {367 int n = d;368 size_t alen = jv_string_length_bytes(jv_copy(str));369 res = jv_string_empty(alen * n);370 for (; n > 0; n--) {371 res = jv_string_append_buf(res, jv_string_value(str), alen);
1492 unmodified lines
modified:tests/jq.test+5 added-1 removed
1284 unmodified lines
1285["aaa", "ababab", "abcabcabc"]12861287[.[] * "abc"]1288[-1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 3.7, 10.0]1289[null,null,null,"abc","abc","abc","abcabcabc","abcabcabcabcabcabcabcabcabcabc"]1289[null,null,"","","abc","abc","abcabcabc","abcabcabcabcabcabcabcabcabcabc"]12901291[. * (nan,-nan)]1292"abc"1293[null,null]12941295[.[] / ","]1296["a, bc, def, ghij, jklmn, a,b, c,d, e,f", "a,b,c,d, e,f,g,h"]1297[["a"," bc"," def"," ghij"," jklmn"," a","b"," c","d"," e","f"],["a","b","c","d"," e","f","g","h"]]1298
465 unmodified lines