Jan Beulich
2013-Dec-02 12:06 UTC
[PATCH] common/vsprintf: fix return value when formatting symbolic addresses
When the buffer to be formatted to is too small, the function return value is expected to be the number of characters that would be printed (particularly important if that value is then used for allocating a buffer). Hence incrementing the active pointer must always be independent of actually storing a character. Signed-off-by: Jan Beulich <jbeulich@suse.com> --- a/xen/common/vsprintf.c +++ b/xen/common/vsprintf.c @@ -294,6 +294,7 @@ static char *pointer(char *str, char *en /* Print ''+<offset>/<len>'' */ str = number(str, end, sym_offset, 16, -1, -1, SPECIAL|SIGN|PLUS); if ( str <= end ) - *str++ = ''/''; + *str = ''/''; + ++str; str = number(str, end, sym_size, 16, -1, -1, SPECIAL); } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
Andrew Cooper
2013-Dec-02 13:07 UTC
Re: [PATCH] common/vsprintf: fix return value when formatting symbolic addresses
On 02/12/13 12:06, Jan Beulich wrote:> When the buffer to be formatted to is too small, the function return > value is expected to be the number of characters that would be printed > (particularly important if that value is then used for allocating a > buffer). Hence incrementing the active pointer must always be > independent of actually storing a character. > > Signed-off-by: Jan Beulich <jbeulich@suse.com>Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>> > --- a/xen/common/vsprintf.c > +++ b/xen/common/vsprintf.c > @@ -294,6 +294,7 @@ static char *pointer(char *str, char *en > /* Print ''+<offset>/<len>'' */ > str = number(str, end, sym_offset, 16, -1, -1, SPECIAL|SIGN|PLUS); > if ( str <= end ) > - *str++ = ''/''; > + *str = ''/''; > + ++str; > str = number(str, end, sym_size, 16, -1, -1, SPECIAL); > } > > > >
Keir Fraser
2013-Dec-02 15:23 UTC
Re: [PATCH] common/vsprintf: fix return value when formatting symbolic addresses
On 02/12/2013 13:07, "Andrew Cooper" <andrew.cooper3@citrix.com> wrote:> On 02/12/13 12:06, Jan Beulich wrote: >> When the buffer to be formatted to is too small, the function return >> value is expected to be the number of characters that would be printed >> (particularly important if that value is then used for allocating a >> buffer). Hence incrementing the active pointer must always be >> independent of actually storing a character. >> >> Signed-off-by: Jan Beulich <jbeulich@suse.com> > > Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>Acked-by: Keir Fraser <keir@xen.org>>> >> --- a/xen/common/vsprintf.c >> +++ b/xen/common/vsprintf.c >> @@ -294,6 +294,7 @@ static char *pointer(char *str, char *en >> /* Print ''+<offset>/<len>'' */ >> str = number(str, end, sym_offset, 16, -1, -1, >> SPECIAL|SIGN|PLUS); >> if ( str <= end ) >> - *str++ = ''/''; >> + *str = ''/''; >> + ++str; >> str = number(str, end, sym_size, 16, -1, -1, SPECIAL); >> } >> >> >> >> > >