[cmake-developers] [PATCH] Avoid bad alloc for large files
Justin Borodinsky
justin.borodinsky at gmail.com
Sat Dec 20 09:03:13 EST 2014
Yes, thank you.
On Saturday, December 20, 2014, Rolf Eike Beer <eike at sf-mail.de> wrote:
> Justin Borodinsky wrote:
> > I received a bad alloc when uploading a large file with CTest. The patch
> > below resolved this.
>
> Your patch is line-wrapped and can't be applied. However, I did this by
> hand.
> This is basically the same, but it avoids the needless floating point
> arithmetic. Does it work for you?
>
> diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx
> index 2bf7b77..1a7bf45 100644
> --- a/Source/cmCTest.cxx
> +++ b/Source/cmCTest.cxx
> @@ -1688,7 +1688,7 @@ std::string
> cmCTest::Base64GzipEncodeFile(std::string file)
> //----------------------------------------------------------------------
> std::string cmCTest::Base64EncodeFile(std::string file)
> {
> - long len = cmSystemTools::FileLength(file);
> + const size_t len = cmSystemTools::FileLength(file);
> cmsys::ifstream ifs(file.c_str(), std::ios::in
> #ifdef _WIN32
> | std::ios::binary
> @@ -1699,8 +1699,7 @@ std::string cmCTest::Base64EncodeFile(std::string
> file)
> ifs.close();
>
> unsigned char *encoded_buffer
> - = new unsigned char [ static_cast<int>(
> - static_cast<double>(len) * 1.5 + 5.0) ];
> + = new unsigned char [ (len * 3) / 2 + 5 ];
>
> unsigned long rlen
> = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
>
>
>
> Eike
> --
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20141220/a5b33342/attachment.html>
More information about the cmake-developers
mailing list