Skip to content
  • Nikolai Kosjar's avatar
    C++: Safe accessing of elements of TranslationUnit::_tokens · 1a5c7d8e
    Nikolai Kosjar authored
    
    
    Until now std::vector::at() was used to access the elements. This is
    handy for debugging since an exception is thrown for invalid indices,
    but it does not stop Qt Creator from crashing because exceptions are not
    caught.
    
    This is especially a problem for the parser, which has to look ahead via
    LA(n), which accesses TranslationUnit::_tokens.
    
    With this patch, explicit bounds checking is done before accessing the
    elements and thus calls to
    
      std::vector::at() // bounds checking, throwing out_of_range
    
    were replaced by calls to
    
      std::vector::operator[]() // no bounds checking, not throwing out_of_range
    
    Measuring the parse time for the Qt Creator project shows that there is
    no slowdown. In both cases, with and without the patch, about 15s are
    needed on the authors machine.
    
    Task-number: QTCREATORBUG-10453
    
    Change-Id: I32b12a526ff7199bcadfc21a3deb5354063a3e3b
    Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
    1a5c7d8e