>> 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?

snip

>  std::string cmCTest::Base64EncodeFile(std::string file)

snip

> -        static_cast<double>(len) * 1.5 + 5.0) ];
> +    = new unsigned char [ (len * 3) / 2 + 5 ];

snip

I came across a similar issue a few days ago in our code base (bad
alloc when compressing a large file in-memory with 256 MB data ulimit
per process) and I used a different formula to calculate the maximum
buffer size:

http://stackoverflow.com/questions/1533113/calculate-the-size-to-a-base-64-encoded-message

I used a bit modified answer from "kanaka".

size_t output_size = ((len - 1) / 3) * 4 + 4;
size_t final_size = output_size + (output_size / 64) * 2; // 64
instead of 76 since RFC 3548 and RFC 4648 allow CLRF line breaks every
64 characters

This formula would give less memory allocation overhead.

Regards,
Domen
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to