lkml.org 
[lkml]   [2024]   [Feb]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2] bcachefs: Avoid a potential useless over memory allocation in bch2_prt_[v]printf()
On Sun, Feb 18, 2024 at 05:12:28PM +0100, Christophe JAILLET wrote:
> 2 issues related to incorrect available space in the output buffer
> computation may lead to some extra memory allocation.
>
>
> First: vsnprintf() takes the size of the buffer, *including* the space for
> the trailing null.
>
> But printbuf_remaining() returns the number of characters we can print
> to the output buffer, *excluding* the terminating null.
>
> So, use printbuf_remaining_size(), which includes the space for the
> terminating null.
>
>
> Second: if the return value of vsnprintf() is greater than or equal to the
> passed size, the resulting string is truncated.
> So, in order to see if some extra space is needed, the check needs to be
> changed.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Thanks, applied

\
 
 \ /
  Last update: 2024-05-27 15:09    [W:0.048 / U:0.708 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site