Mozilla 2/Strings/Static Analysis: Difference between revisions
Jump to navigation
Jump to search
(suggested definition of modification) |
(updated mod suggestion) |
||
| Line 6: | Line 6: | ||
* check to see whether that string is modified after the conversion takes place | * check to see whether that string is modified after the conversion takes place | ||
TODO: define "modification" [dmandelin] Can modification be defined as calling a non-const method | TODO: define "modification" [dmandelin] Can modification be defined as any of (1) calling a non-const method, (2) passing as a non-const argument, (3) being a parameter, or (4) escaping (by having a pointer stored or a pointer or reference returned)? | ||
repeat for utf16->ut8 | repeat for utf16->ut8 | ||
Revision as of 03:50, 14 February 2008
How many strings exist *only* for conversion?
Procedure:
- find calls to NS_ConvertUTF8toUTF16 and CopyUTF8toUTF16
- check to see whether that string is modified after the conversion takes place
TODO: define "modification" [dmandelin] Can modification be defined as any of (1) calling a non-const method, (2) passing as a non-const argument, (3) being a parameter, or (4) escaping (by having a pointer stored or a pointer or reference returned)?
repeat for utf16->ut8
If "AString" were immutable, where would we fail?
Imagine that all nsAStrings currently allocated on the stack became a different type (nsAStringBuilder or std::wstring or something). But when we pass strings around, they are immutable. Classify any cases where this wouldn't work:
Take the following methods:
nsresult GetAString(nsAString &result)
{
result.Assign("foo"); // this is ok, it can be converted to return a new
// immutable string
}
nsresult AppendToAString(nsAString &result)
{
result.Append("foo"); // this won't work... it modifies the inout param so
// we would have to rewrite "result" to be
// nsAStringBuilder&, or split it into two separate
// params, one in, one out.
}