Use size_t for all sizes. The '*' modifier unfortunately does require an
int so a temporary variable is necessary in the tests.
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
src/util/virbuffer.c | 2 +-
src/util/virbuffer.h | 6 +++---
tests/virbuftest.c | 4 +++-
3 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c
index 8bb9c8e1fa..2e1e4abead 100644
--- a/src/util/virbuffer.c
+++ b/src/util/virbuffer.c
@@ -339,7 +339,7 @@ virBufferCheckErrorInternal(const virBuffer *buf,
*
* Return the string usage in bytes
*/
-unsigned int
+size_t
virBufferUse(const virBuffer *buf)
{
if (buf == NULL)
diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h
index 16cd8515d6..18957ae02c 100644
--- a/src/util/virbuffer.h
+++ b/src/util/virbuffer.h
@@ -38,8 +38,8 @@ typedef virBuffer *virBufferPtr;
# define VIR_BUFFER_INITIALIZER { 0, 0, 0, 0, NULL }
struct _virBuffer {
- unsigned int size;
- unsigned int use;
+ size_t size;
+ size_t use;
unsigned int error; /* errno value, or -1 for usage error */
int indent;
char *content;
@@ -69,7 +69,7 @@ VIR_DEFINE_AUTOCLEAN_FUNC(virBuffer, virBufferFreeAndReset);
# define virBufferCheckError(buf) \
virBufferCheckErrorInternal(buf, VIR_FROM_THIS, __FILE__, __FUNCTION__, \
__LINE__)
-unsigned int virBufferUse(const virBuffer *buf);
+size_t virBufferUse(const virBuffer *buf);
void virBufferAdd(virBufferPtr buf, const char *str, int len);
void virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd);
void virBufferAddChar(virBufferPtr buf, char c);
diff --git a/tests/virbuftest.c b/tests/virbuftest.c
index b608da94d4..778754d7c1 100644
--- a/tests/virbuftest.c
+++ b/tests/virbuftest.c
@@ -20,6 +20,7 @@ static int testBufInfiniteLoop(const void *data)
char *addstr = NULL, *bufret = NULL;
int ret = -1;
const struct testInfo *info = data;
+ int len;
virBufferAddChar(buf, 'a');
@@ -29,7 +30,8 @@ static int testBufInfiniteLoop(const void *data)
* which was the case after the above addchar at the time of the bug.
* This test is a bit fragile, since it relies on virBuffer internals.
*/
- if (virAsprintf(&addstr, "%*s", buf->size - buf->use - 1, "a") < 0)
+ len = buf->size - buf->use - 1;
+ if (virAsprintf(&addstr, "%*s", len, "a") < 0)
goto out;
if (info->doEscape)
--
2.20.1
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
On 3/29/19 9:33 AM, Peter Krempa wrote:
> Use size_t for all sizes. The '*' modifier unfortunately does require an
> int so a temporary variable is necessary in the tests.
>
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
> src/util/virbuffer.c | 2 +-
> src/util/virbuffer.h | 6 +++---
> tests/virbuftest.c | 4 +++-
> 3 files changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c
> index 8bb9c8e1fa..2e1e4abead 100644
> --- a/src/util/virbuffer.c
> +++ b/src/util/virbuffer.c
> @@ -339,7 +339,7 @@ virBufferCheckErrorInternal(const virBuffer *buf,
> *
> * Return the string usage in bytes
> */
> -unsigned int
> +size_t
> virBufferUse(const virBuffer *buf)
> {
> if (buf == NULL)
> diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h
> index 16cd8515d6..18957ae02c 100644
> --- a/src/util/virbuffer.h
> +++ b/src/util/virbuffer.h
> @@ -38,8 +38,8 @@ typedef virBuffer *virBufferPtr;
> # define VIR_BUFFER_INITIALIZER { 0, 0, 0, 0, NULL }
>
> struct _virBuffer {
> - unsigned int size;
> - unsigned int use;
> + size_t size;
> + size_t use;
> unsigned int error; /* errno value, or -1 for usage error */
> int indent;
> char *content;
> @@ -69,7 +69,7 @@ VIR_DEFINE_AUTOCLEAN_FUNC(virBuffer, virBufferFreeAndReset);
> # define virBufferCheckError(buf) \
> virBufferCheckErrorInternal(buf, VIR_FROM_THIS, __FILE__, __FUNCTION__, \
> __LINE__)
> -unsigned int virBufferUse(const virBuffer *buf);
> +size_t virBufferUse(const virBuffer *buf);
> void virBufferAdd(virBufferPtr buf, const char *str, int len);
> void virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd);
> void virBufferAddChar(virBufferPtr buf, char c);
> diff --git a/tests/virbuftest.c b/tests/virbuftest.c
> index b608da94d4..778754d7c1 100644
> --- a/tests/virbuftest.c
> +++ b/tests/virbuftest.c
> @@ -20,6 +20,7 @@ static int testBufInfiniteLoop(const void *data)
> char *addstr = NULL, *bufret = NULL;
> int ret = -1;
> const struct testInfo *info = data;
> + int len;
>
> virBufferAddChar(buf, 'a');
>
> @@ -29,7 +30,8 @@ static int testBufInfiniteLoop(const void *data)
> * which was the case after the above addchar at the time of the bug.
> * This test is a bit fragile, since it relies on virBuffer internals.
> */
> - if (virAsprintf(&addstr, "%*s", buf->size - buf->use - 1, "a") < 0)
> + len = buf->size - buf->use - 1;
> + if (virAsprintf(&addstr, "%*s", len, "a") < 0)
If you really wanted to avoid the temporary int (which you've implied
you don't like in the commit message), you could just do a typecast in
the arg list.
Reviewed-by: Laine Stump <laine@laine.org>
> goto out;
>
> if (info->doEscape)
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
On Sat, Mar 30, 2019 at 12:21:51 -0400, Laine Stump wrote: > On 3/29/19 9:33 AM, Peter Krempa wrote: > > Use size_t for all sizes. The '*' modifier unfortunately does require an > > int so a temporary variable is necessary in the tests. > > > > Signed-off-by: Peter Krempa <pkrempa@redhat.com> > > --- > > src/util/virbuffer.c | 2 +- > > src/util/virbuffer.h | 6 +++--- > > tests/virbuftest.c | 4 +++- > > 3 files changed, 7 insertions(+), 5 deletions(-) [...] > > @@ -29,7 +30,8 @@ static int testBufInfiniteLoop(const void *data) > > * which was the case after the above addchar at the time of the bug. > > * This test is a bit fragile, since it relies on virBuffer internals. > > */ > > - if (virAsprintf(&addstr, "%*s", buf->size - buf->use - 1, "a") < 0) > > + len = buf->size - buf->use - 1; > > + if (virAsprintf(&addstr, "%*s", len, "a") < 0) > > > If you really wanted to avoid the temporary int (which you've implied you > don't like in the commit message), you could just do a typecast in the arg > list. That looke worse. -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
On 4/1/19 2:59 AM, Peter Krempa wrote: > On Sat, Mar 30, 2019 at 12:21:51 -0400, Laine Stump wrote: >> On 3/29/19 9:33 AM, Peter Krempa wrote: >>> Use size_t for all sizes. The '*' modifier unfortunately does require an >>> int so a temporary variable is necessary in the tests. >>> >>> Signed-off-by: Peter Krempa <pkrempa@redhat.com> >>> --- >>> src/util/virbuffer.c | 2 +- >>> src/util/virbuffer.h | 6 +++--- >>> tests/virbuftest.c | 4 +++- >>> 3 files changed, 7 insertions(+), 5 deletions(-) > [...] > >>> @@ -29,7 +30,8 @@ static int testBufInfiniteLoop(const void *data) >>> * which was the case after the above addchar at the time of the bug. >>> * This test is a bit fragile, since it relies on virBuffer internals. >>> */ >>> - if (virAsprintf(&addstr, "%*s", buf->size - buf->use - 1, "a") < 0) >>> + len = buf->size - buf->use - 1; >>> + if (virAsprintf(&addstr, "%*s", len, "a") < 0) >> >> If you really wanted to avoid the temporary int (which you've implied you >> don't like in the commit message), you could just do a typecast in the arg >> list. > That looke worse. Agreed. It just sounded like maybe you regretted putting in the int, so I was offering you an out :-) -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
© 2016 - 2026 Red Hat, Inc.