Skip to content

Commit 69e3764

Browse files
committed
Ported #1397 to SAM.
1 parent 3d222cc commit 69e3764

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Diff for: hardware/arduino/sam/cores/arduino/WString.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ String String::substring(unsigned int left, unsigned int right) const
621621
left = temp;
622622
}
623623
String out;
624-
if (left > len) return out;
624+
if (left >= len) return out;
625625
if (right > len) right = len;
626626
char temp = buffer[right]; // save the replaced character
627627
buffer[right] = '\0';
@@ -686,15 +686,16 @@ void String::replace(const String& find, const String& replace)
686686
}
687687

688688
void String::remove(unsigned int index){
689-
if (index >= len) { return; }
690-
int count = len - index;
691-
remove(index, count);
689+
// Pass the biggest integer as the count. The remove method
690+
// below will take care of truncating it at the end of the
691+
// string.
692+
remove(index, (unsigned int)-1);
692693
}
693694

694695
void String::remove(unsigned int index, unsigned int count){
695696
if (index >= len) { return; }
696697
if (count <= 0) { return; }
697-
if (index + count > len) { count = len - index; }
698+
if (count > len - index) { count = len - index; }
698699
char *writeTo = buffer + index;
699700
len = len - count;
700701
strncpy(writeTo, buffer + index + count,len - index);

0 commit comments

Comments
 (0)