qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [RFC] qed: Add QEMU Enhanced Disk format


From: Alexander Graf
Subject: Re: [Qemu-devel] [RFC] qed: Add QEMU Enhanced Disk format
Date: Mon, 6 Sep 2010 16:24:20 +0200

On 06.09.2010, at 16:21, Luca Tettamanti wrote:

> On Mon, Sep 6, 2010 at 12:25 PM, Alexander Graf <address@hidden> wrote:
>> On 06.09.2010, at 12:04, Stefan Hajnoczi wrote:
>>> +
>>> +const char *bytes_to_str(uint64_t size)
>>> +{
>>> +    static char buffer[64];
>>> +
>>> +    if (size < (1ULL << 10)) {
>>> +        snprintf(buffer, sizeof(buffer), "%" PRIu64 " byte(s)", size);
>>> +    } else if (size < (1ULL << 20)) {
>>> +        snprintf(buffer, sizeof(buffer), "%" PRIu64 " KB(s)", size >> 10);
>>> +    } else if (size < (1ULL << 30)) {
>>> +        snprintf(buffer, sizeof(buffer), "%" PRIu64 " MB(s)", size >> 20);
>>> +    } else if (size < (1ULL << 40)) {
>>> +        snprintf(buffer, sizeof(buffer), "%" PRIu64 " GB(s)", size >> 30);
>>> +    } else {
>>> +        snprintf(buffer, sizeof(buffer), "%" PRIu64 " TB(s)", size >> 40);
>>> +    }
>>> +
>>> +    return buffer;
>> 
>> This returns a variable from the stack! Please make the target buffer caller 
>> defined.
> 
> It's static, so it's formally correct. But probably not a good idea :)

Oh - I missed the static there. Yeah, it's even worse. This is racy.

Alex




reply via email to

[Prev in Thread] Current Thread [Next in Thread]