On 06.09.2010, at 16:21, Luca Tettamanti wrote: > On Mon, Sep 6, 2010 at 12:25 PM, Alexander Graf <ag...@suse.de> 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