mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-01-23 02:14:37 +00:00
compel: std_vprint_num returns a null-terminated string
This function is an analogue to vsprintf(), and is used in very much the same way. The caller expects the modified string pointer to be pointing to a null-terminated string. Signed-off-by: Joel Nider <joeln@il.ibm.com> Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
parent
5d3ea878fb
commit
a80f1da90c
1 changed files with 3 additions and 3 deletions
|
|
@ -143,6 +143,7 @@ int std_vprint_num(char *buf, int blen, int num, char **ps)
|
|||
char *s;
|
||||
|
||||
s = &buf[blen - 1];
|
||||
*s-- = 0; /* make sure the returned string is NULL terminated */
|
||||
|
||||
if (num < 0) {
|
||||
neg = 1;
|
||||
|
|
@ -166,15 +167,14 @@ int std_vprint_num(char *buf, int blen, int num, char **ps)
|
|||
done:
|
||||
s++;
|
||||
*ps = s;
|
||||
return blen - (s - buf);
|
||||
return blen - (s - buf) - 1;
|
||||
}
|
||||
|
||||
static void print_num(int num, struct simple_buf *b)
|
||||
{
|
||||
char buf[12], *s;
|
||||
|
||||
buf[11] = '\0';
|
||||
std_vprint_num(buf, sizeof(buf) - 1, num, &s);
|
||||
std_vprint_num(buf, sizeof(buf), num, &s);
|
||||
print_string(s, b);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue