Skip to content

g_string_replace: Don't replace empty string more than once per location

Simon McVittie requested to merge wip/smcv/2452-g-string-0-length-replace into main
  • test_string_replace: Make types agree

    g_string_replace() returns guint, not gint.

  • test_string_replace: Make the test table-driven

    This makes it straightforward to add more test-cases.

  • test_string_replace: Expand test coverage

    These are taken from another project (steam-runtime-tools) where I implemented a similar replace method before realising that more recent GLib versions had g_string_replace().

  • g_string_replace: Don't replace empty string more than once per location

    This matches the behaviour of Python str.replace(), and avoids carrying out 2**32 replacements before n wraps around, which is almost certainly not what we want.

    Resolves: #2452 (closed)

  • test_string_replace: Exercise zero-length replacements

    Previously, these would have done 2**32 replacements, and the first one would have consumed 6GB of memory in the process. They now match what Python str.replace() does.

    Reproduces: #2452 (closed)

Merge request reports