lkml.org 
[lkml]   [2014]   [Oct]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH 8/8] tools, perf: Add asprintf replacement
From
On Mon, Oct 20, 2014 at 8:28 PM, Jiri Olsa <jolsa@redhat.com> wrote:
>> +int vasprintf(char **str, const char *fmt, va_list ap)
>> +{
>> + char buf[1024];
>
> could you please make it work for generic buf len?

The actual size above doesn't matter, except for stack usage.
It could be 1 (are there any bugs triggered when using zero? ;-).
The real buffer is allocated by malloc() below.

>> + int len = vsnprintf(buf, sizeof buf, fmt, ap);
>
> WARNING: sizeof buf should be sizeof(buf)
>
>> +
>> + *str = malloc(len + 1);
>> + if (!*str)
>> + return -1;
>> + strcpy(*str, buf);
>> + return len;
>> +}

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


\
 
 \ /
  Last update: 2014-10-20 21:21    [W:0.053 / U:0.468 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site