Show
Ignore:
Timestamp:
08/24/02 23:41:13 (6 years ago)
Author:
darin
Message:
  • fixed 3032072 -- Crash on reload in DOM::DocumentImpl::~DocumentImpl [unified]()

This was a tough one to debug.
Turned out to be a subtle bug in our new QConstString implementation.

  • kwq/KWQString.mm: (QStringData::makeAscii): Don't invalidate the Unicode buffer unless the ASCII buffer is taking over the internal buffer from the Unicode. In other cases, it's important not to invalidate the Unicode because it can result in the Unicode being freed and re-created when unicode() is called, which is disastrous in the QConstString case because we can't free the Unicode. (QStringData::makeUnicode): Make the corresponding change for ASCII too. In this case, it's just an optimization, not a bug fix. (QString::insert), (QString::remove), (QString::fill), (QString::operator+=): Mark the other string invalid whenever we modify either the ASCII or the Unicode string. This was handled correctly for some operations before, but not all, and it now matters because makeAscii and makeUnicode will now allow this state.

Fixed a separate QString problem; I think I may have introduced this one.

  • kwq/KWQString.mm: (QString::getNSString): Since by ASCII, we actually mean ISO Latin 1, we can't use [NSString stringWithCString:]. Use CFStringCreateWithCString instead, pass CFStringCreateWithCString as the encoding, and use autorelease. We shouldn't really use the term ASCII in this class for the 8-bit-per-character buffer. Something more like Latin1 would be a more accurate way to refer to it. Maybe I'll do that renaming after talking to Richard about it on Monday.

Fixed a small storage leak.

  • khtml/css/css_valueimpl.cpp: (CSSPrimitiveValueImpl::cleanup): Added braces to fix obviously-incorrect if/else grouping.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/kwq/KWQString.mm

    r1903 r1912  
    596596                    *tp++ = *fp++; 
    597597                str = &copyBuf[0]; 
     598                _isUnicodeValid = 0; 
    598599            } 
    599600            else 
     
    616617        *cp = 0; 
    617618         
    618         _isUnicodeValid = 0; 
    619619        _isAsciiValid = 1; 
    620620    } 
     
    644644                    *tp++ = *fp++; 
    645645                str = &copyBuf[0]; 
     646                _isAsciiValid = 0; 
    646647            } 
    647648            else 
     
    663664         
    664665        _isUnicodeValid = 1; 
    665         _isAsciiValid = 0; 
    666666    } 
    667667    else if (!_isUnicodeValid) 
     
    778778     
    779779    if (dataHandle[0]->_isAsciiValid) { 
    780         return [NSString stringWithCString:(const char *)ascii()]; 
     780        return [(NSString *)CFStringCreateWithCString(kCFAllocatorDefault, ascii(), kCFStringEncodingISOLatin1) autorelease]; 
    781781    } 
    782782     
     
    20622062        // Insert characters. 
    20632063        memcpy (targetChars+index, insertChars, insertLength); 
     2064         
     2065        dataHandle[0]->_isUnicodeValid = 0; 
    20642066    } 
    20652067    else if (dataHandle[0]->_isUnicodeValid){ 
     
    21282130        } 
    21292131         
     2132        dataHandle[0]->_isAsciiValid = 0; 
    21302133    } 
    21312134     
     
    21532156        targetChars[index] = insertChar; 
    21542157        targetChars[dataHandle[0]->_length] = 0; 
     2158 
     2159        dataHandle[0]->_isUnicodeValid = 0; 
    21552160    } 
    21562161    else { 
     
    21912196        targetChars[index] = ch; 
    21922197        targetChars[dataHandle[0]->_length] = 0; 
     2198 
     2199        dataHandle[0]->_isUnicodeValid = 0; 
    21932200    } 
    21942201    else if (dataHandle[0]->_isUnicodeValid){ 
     
    22922299                    sizeof(char)*(olen-index-len) ); 
    22932300            setLength( olen-len ); 
     2301            dataHandle[0]->_isUnicodeValid = 0; 
    22942302        } 
    22952303        else if (dataHandle[0]->_isUnicodeValid){ 
     
    24172425            while (len--)  
    24182426                *nd++ = (char)qc; 
     2427            dataHandle[0]->_isUnicodeValid = 0; 
    24192428        } 
    24202429        else { 
     
    24612470            QSTRING_FAILURE("invalid character cache"); 
    24622471        dataHandle[0]->_length += qs.data()->_length; 
     2472        dataHandle[0]->_isAsciiValid = 0; 
    24632473        return *this; 
    24642474    } 
     
    24712481        *tp = 0; 
    24722482        dataHandle[0]->_length += qs.data()->_length; 
     2483        dataHandle[0]->_isUnicodeValid = 0; 
    24732484        return *this; 
    24742485    }