This function crashes me when I call it, and i can't figure out why.

Code:
vector<string> line_split(const string& s)
{
	vector<string> ret;
	string::size_type size = s.size();
	int i =0, j=0;

	while (j != size)
	{
		while (j != size && s[j] != '\r' )
			j++;	

		if (i != j)
			ret.push_back(s.substr(i, j-i));
		i = j;
	}

	return ret;
}
If I comment out the first while loop, it works, but when I include it, it doesn't. Any ideas?