Skip to content

Conversation

itchyny
Copy link
Contributor

@itchyny itchyny commented May 8, 2020

This pull request fixes #2117. And maybe #2115 as well (I can't confirm yet).

@itchyny itchyny force-pushed the fix-multiple-string-multiplication branch from 6d7921b to 0b3027f Compare May 8, 2020 05:33
@coveralls
Copy link

coveralls commented May 8, 2020

Coverage Status

Coverage increased (+0.03%) to 84.158% when pulling d2cec5c on itchyny:fix-multiple-string-multiplication into ccc79e5 on stedolan:master.

@itchyny itchyny force-pushed the fix-multiple-string-multiplication branch from 0b3027f to f798690 Compare May 8, 2020 05:39
@whentze
Copy link

whentze commented May 8, 2020

I just tried the reproducing example from #2115 against this branch and it doesn't crash (and prints the correct result). Sanitizers and valgrind are looking clean too.

@wtlangford
Copy link
Contributor

Good find! I'll suggest a slightly more efficient solution:

jv res = jv_null();
int n = jv_number_value(num);
if (n > 0) {
  size_t alen = jv_string_length_bytes(jv_copy(str));
  res = jv_string_empty(alen * n);

  for (; n > 0; n--) {
    res = jv_string_append_buf(res, jv_string_value(str), alen);
  }
}
jv_free(str);
jv_free(num);
return res;

@itchyny
Copy link
Contributor Author

itchyny commented May 9, 2020

@wtlangford I update the patch, thanks. But considering the performance here seriously, we should reduce the number of jvp_utf8_is_valid checks.

@wtlangford
Copy link
Contributor

@wtlangford I update the patch, thanks. But considering the performance here seriously, we should reduce the number of jvp_utf8_is_valid checks.

Agreed, we should- but for now, I think this is good. Thanks for tracking this down!

@wtlangford wtlangford merged commit 6306ac8 into jqlang:master May 26, 2020
@itchyny
Copy link
Contributor Author

itchyny commented Jun 12, 2020

I noticed that 0.5 * "abc" is changed by this pull request. Should we keep the original behavior?

@wtlangford
Copy link
Contributor

Yes, we definitely should

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

String multiplication produces unexpected result
4 participants