Mozilla 2/Strings/Static Analysis

From MozillaWiki
< Mozilla 2‎ | Strings
Revision as of 13:55, 12 February 2008 by Jag (talk | contribs) (Alright, let's try this wording.)
Jump to navigation Jump to search

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"

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.
}