• Mike Kaganski's avatar
    Make Windows error reporting more robust · e3530d2c
    Mike Kaganski yazdı
    https://msdn.microsoft.com/en-us/library/ms679351 describes that
    "it is unsafe to take an arbitrary system error code returned from an API
    and use FORMAT_MESSAGE_FROM_SYSTEM without FORMAT_MESSAGE_IGNORE_INSERTS"
    Previously in case when an error string would contain inserts, function
    returned error, so the error message wasn't shown (at least it didn't
    crash, thanks to nullptr as the function's last argument).
    
    As the function may fail, we now pre-nullify the buffer pointer to avoid
    dereferencing uninitialized pointer later (though at least for some
    Windows versions, the function nullifies the pointer in case of
    FORMAT_MESSAGE_ALLOCATE_BUFFER, but there's no explicit guarantee of this).
    
    Also release of allocated buffer is changed to recommended use of
    HeapFree.
    
    The code that doesn't make use of OUString is left directly calling
    FormatMessage, to avoid introducing new dependencies. Where it makes
    sense, we now use WindowsErrorString from <comphelper/windowserrorstring.hxx>
    
    Change-Id: I834c08eb6d92987e7d3d01e2c36ec55e42aea848
    Reviewed-on: https://gerrit.libreoffice.org/44206Tested-by: 's avatarJenkins <ci@libreoffice.org>
    Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
    Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
    e3530d2c