Bug with String.append()


#1

Hi Jules,

I'm trying to move a project I'm working on over to windows. After getting a windows install and visual studio setup, I noticed one of my unit tests fails. It appears the root cause is due to the String.append function misbehaving on Windows with a very specific string. I was able to reproduce the issue with a few lines of code, using Juce v3.1.1 and a generated commandline project from IntroJucer (targeting VS2015):


    String string("abc\"");
    String string2("abcdefghijklmn\"");
    string.append(string, 1);
    string2.append(string2, 1);
    DBG(string);
    DBG(string2);

This produces the following output:

abc"a
abcdefghijklmn"

As you can see the second string should have an 'a' appended but it does not.

Full disclosure, I couldn't find my XP key, so I'm just running the pre-release Windows 10 and VS2015 Ultimate Preview (latest releases of both).

It's no big issue for me, as I found an easy work around of using:

string = string + string[0];

... but thought I would make you aware.

Jim


#2

Hi Jules,

Small update. I tried with the latest version of JUCE from Github (per your bug posting sticky). Still reproduciable. 

I also ran JUCE_UNIT_TESTS and saw that it does not fail with my setup, everything passes (can't recall if there is a test for append though).

Finally, if I make a copy of the string and reference that copy and not the string itself in the append function, everything works as expected.

Best regards,

Jim

 


#3

Thanks Jim - yes, it looks like the problem is just because it's attempting to append a string to itself - i.e. it's writing into the same buffer that it's also reading from, which won't end well!

This is actually a bit of an edge-case because it'll only go wrong if there's only one reference to the string, and that's an unusual situation that's unlikely to arise outside of test code like this, but thanks for the heads-up, I'll add some code to make it handle it!