[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug classpath/61468] New: StringBuilder.setLength() doesn't clear strin
From: |
zuencap at yahoo dot com |
Subject: |
[Bug classpath/61468] New: StringBuilder.setLength() doesn't clear string data |
Date: |
Wed, 11 Jun 2014 09:23:31 +0000 |
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61468
Bug ID: 61468
Summary: StringBuilder.setLength() doesn't clear string data
Product: classpath
Version: 0.98
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: classpath
Assignee: unassigned at gcc dot gnu.org
Reporter: zuencap at yahoo dot com
This test fails:
StringBuilder s = new StringBuilder("StringBuilder");
s.setLength(5);
s.setLength(13);
assertEquals("Strin\000\000\000\000\000\000\000\000", s.toString());
Recommended fix:
public void setLength(int newLength) {
if (newLength < 0)
throw new StringIndexOutOfBoundsException(newLength);
if( newLength > value.length ) {
/* If the StringBuilder's value needs to grow, then we know that
value will be newly allocated and the region between count and
newLength wil be filled with '\0'. */
ensureCapacity(newLength);
} else {
/* The StringBuilder's value doesn't need to grow. However,
we should clear out any cruft that may exist. */
while (count < newLength) {
value[count++] = '\0';
}
// if count > newLength, it will be set to newLength at the end
}
count = newLength;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug classpath/61468] New: StringBuilder.setLength() doesn't clear string data,
zuencap at yahoo dot com <=