[squid-dev] Do not load icons one character at a time
Alex Rousskov
rousskov at measurement-factory.com
Mon May 23 14:48:53 UTC 2016
On 05/23/2016 02:48 AM, Amos Jeffries wrote:
> On 22/05/2016 5:03 a.m., Alex Rousskov wrote:
>> On 05/21/2016 03:09 AM, Amos Jeffries wrote:
>>> On 21/05/2016 6:25 a.m., Alex Rousskov wrote:
>>>>> Since trunk r14100 (Bug 3875: bad mimeLoadIconFile error handling), each
>>>>> icon was read from disk and written to Store one character at a time.
>>
>>
>>> - char *buf = (char *)memAllocate(MEM_4K_BUF);
>>> - while ((n = FD_READ_METHOD(fd, buf, sizeof(*buf))) > 0)
>>
>>
>>> Do you know where it is coming from exactly?
>>> sizeof(*buf) on dynamic arrays should be the array length. Not the char
>>> size.
>>
>> ... because the compiler adds secret code that stores sizes of all
>> dynamically allocated buffers in a secret hash and then looks that hash
>> up whenever somebody calls sizeof() for any pointer, including sizeof()
>> calls in another library compiled by another compiler and running in
>> another thread? Think about it.
> IIRC you would be referring to the malloc block header. Which our pools
> allocator does not have. Figures.
I was referring to magical abilities that do not and cannot exist :-(.
C++ does not know anything about "malloc block header", and there are
many different memory allocation libraries/techniques, so the compiler
simply cannot do what you thought it was doing -- it cannot know the
size of some dynamically allocated memory buffer that "buf" may or may
not point to.
Alex.
More information about the squid-dev
mailing list