Skip to content

bug, infinity loop in string library stringex.h #1

@myfoundation

Description

@myfoundation

stringex & wstringex both.

Sample:

std::stringex tmp = "a";
tmp.replace("a", "aa"); // INFINITY LOOP HERE

because

` stringex &replace(const string &needle, const string &s)
{
size_type
lastpos = 0,
thispos;

		while ((thispos = find(needle, lastpos)) != npos)
		{
			string::replace(thispos, needle.length(), s);
			lastpos = thispos + 1;
		}
		return *this;
	}

`
but need

` stringex &replace(const string &needle, const string &s)
{
size_type
lastpos = 0,
thispos;

		while ((thispos = find(needle, lastpos)) != npos)
		{
			string::replace(thispos, needle.length(), s);
			lastpos = thispos + s.length();
		}
		return *this;
	}

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions