Mozilla 2/Strings/Static Analysis

From MozillaWiki
< Mozilla 2‎ | Strings
Revision as of 22:00, 6 February 2008 by Benjamin Smedberg (talk | contribs) (static analysis of string stuff)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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... we are merely returning a new immutable
                        // value in the outparam
}

nsresult AppendToAString(nsAString &result)
{
  result.Append("foo"); // this isn't ok... it modifies the inout param so
                        // we would have to rewrite "result" to be
                        // nsAStringBuilder&
}