• Luboš Luňák's avatar
    do not access uninitialized values when printing (tdf#121439) · 9e9fb722
    Luboš Luňák yazdı
    The assert in the bugreport is triggered by ScPrintFunc::CalcPages() passing
    uninitialized values of nEndRow (and others). These variables apparently
    get initialized only by constructors that take ScPrintState. These ctors
    also set (the somewhat poorly named) bState and the call to CalcPages()
    is guarded by this. However, GetPrintState() will simply create ScPrintState
    filled with these uninitialized values and later on this will be used
    with these ctors, so bState will be set, but nEndRow will be bogus.
    
    Although 5217a2a0 introduced tdf#121439,
    this strange bState logic and unitialized variables has been these since
    the initial commit, and the code doesn't take any precautions to check
    whether the values are valid or not, so I assume this always was just lucky
    enough to work and 5217a2a0 finally triggered a problem.
    
    Given that it's rather unclear to me how this is supposed to work properly,
    just add an extra flag to both ScPrintFunc and ScPrintState marking whether
    the values are set or not and make CalcPages() depends on this flag instead.
    
    Change-Id: I0620de6562865c24f5a0edca2566b01546bf2e2b
    Reviewed-on: https://gerrit.libreoffice.org/68739Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
    Tested-by: Jenkins
    (cherry picked from commit 9432bab9)
    Reviewed-on: https://gerrit.libreoffice.org/69261Reviewed-by: 's avatarXisco Faulí <xiscofauli@libreoffice.org>
    9e9fb722