Skip to content
  • Romain Vimont's avatar
    gui/qt: bookmarks: fix psz_name lifetime · ea0a32e1
    Romain Vimont authored and Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf committed
    
    
    The macro qtu() is defined as follows:
    
        #define qtu( i ) ((i).toUtf8().constData())
    
    "i" is a QString, .toUtf8() returns a QByteArray, .constData() returns a
    pointer to the data inside the QByteArray.
    
    It is important to notice that the QByteArray is temporary. Therefore,
    it is "destroyed as the last step in evaluating the full-expression that
    (lexically) contains the point where [it was] created".
    
    Concretely, this means that this call is correct:
    
        do_something( qtu( string ) );
    
    But this one is undefined behavior:
    
        const char *s = qtu( string );
        do_something( s );
    
    Thus, here, bookmark.psz_name was initialized with a pointer to garbage
    data.
    
    To fix the problem, store the QByteArray in a local variable so that it
    lives long enough.
    
    (Fixes invalid reads reported by valgrind)
    
    Signed-off-by: default avatarRomain Vimont <rom@rom1v.com>
    Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
    ea0a32e1