lkml.org 
[lkml]   [2007]   [Oct]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH 1/4] stringbuf: A string buffer implementation
Date
On Oct 24, 2007, at 15:59:49, Matthew Wilcox wrote:
> +static void sb_vprintf(struct stringbuf *sb, gfp_t gfp, const char
> *format, va_list args)
> +{

[...]

> + s = sb->buf + sb->len;
> + size = vsnprintf(s, sb->alloc - sb->len, format, args);

[...]

> + /* Point to the end of the old string since we already updated -
> >len */
> + s += sb->len - size;
> + vsprintf(s, format, args);

[...]

> +void sb_printf(struct stringbuf *sb, gfp_t gfp, const char
> *format, ...)
> +{
> + va_list args;
> +
> + va_start(args, format);
> + sb_vprintf(sb, gfp, format, args);
> + va_end(args);
> +}

This seems unlikely to work reliably as the various "v*printf"
functions modify the va_list argument they are passed. It may happen
to work on your particular architecture depending on how that
argument data is passed and stored, but you probably actually want to
make a copy of the varargs list for the first vsnprintf call.
Example below:

> va_list argscopy;
> va_copy(argscopy, args);
>
> [...]
>
> size = vsnprintf(s, sb->alloc - sb->len, format, argscopy)
>
> [...]
>
> s += sb->len - size;
> vsprintf(s, format, args);
>
> [...]
>
> va_end(argscopy);

Cheers,
Kyle Moffett
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2007-10-24 23:25    [W:0.181 / U:2.632 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site