From 52c8a570e123a7afe75cf758f38e62ee075fc5f4 Mon Sep 17 00:00:00 2001 From: Gabriele Date: Fri, 13 Feb 2015 16:04:59 +0100 Subject: [PATCH] Use out of range value when the number of files can't be determined Trying to get the number of files of a torrent with no metadata causes a crash. Prevent this by first checking if the metadata is available. If the number of files can't be determined, -1 will be returned. Closes #2522. --- src/core/qtlibtorrent/qtorrenthandle.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/qtlibtorrent/qtorrenthandle.cpp b/src/core/qtlibtorrent/qtorrenthandle.cpp index 4680e76ca..9e3eab6c7 100644 --- a/src/core/qtlibtorrent/qtorrenthandle.cpp +++ b/src/core/qtlibtorrent/qtorrenthandle.cpp @@ -243,6 +243,8 @@ bool QTorrentHandle::has_filtered_pieces() const int QTorrentHandle::num_files() const { + if (!has_metadata()) + return -1; #if LIBTORRENT_VERSION_NUM < 10000 return torrent_handle::get_torrent_info().num_files(); #else