From 39afb72c4ea429c0ea4f4da4054da0171bfb0a80 Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Wed, 24 Feb 2010 16:17:17 +0000 Subject: [PATCH] Fixed crashes in Ftp::Upload and Ftp::Download with empty files git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1424 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/Network/Ftp.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/SFML/Network/Ftp.cpp b/src/SFML/Network/Ftp.cpp index 85146d4e..c53322c4 100644 --- a/src/SFML/Network/Ftp.cpp +++ b/src/SFML/Network/Ftp.cpp @@ -380,7 +380,8 @@ Ftp::Response Ftp::Download(const std::string& DistantFile, const std::string& D std::ofstream File((Path + Filename).c_str(), std::ios_base::binary); if (!File) return Response(Response::InvalidFile); - File.write(&FileData[0], static_cast(FileData.size())); + if (!FileData.empty()) + File.write(&FileData[0], static_cast(FileData.size())); } } } @@ -402,7 +403,8 @@ Ftp::Response Ftp::Upload(const std::string& LocalFile, const std::string& DestP std::size_t Length = File.tellg(); File.seekg(0, std::ios::beg); std::vector FileData(Length); - File.read(&FileData[0], static_cast(Length)); + if (Length > 0) + File.read(&FileData[0], static_cast(Length)); // Extract the filename from the file path std::string Filename = LocalFile; @@ -700,7 +702,8 @@ void Ftp::DataChannel::Receive(std::vector& Data) void Ftp::DataChannel::Send(const std::vector& Data) { // Send data - myDataSocket.Send(&Data[0], Data.size()); + if (!Data.empty()) + myDataSocket.Send(&Data[0], Data.size()); // Close the data socket myDataSocket.Close();