Message ID | 11a52f72d4a301518ad3fa3ec08080cf1d02e3d1.1576678644.git.qemu_oss@crudebyte.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | 9pfs: readdir optimization | expand |
On Wed, 18 Dec 2019 14:06:30 +0100 Christian Schoenebeck <qemu_oss@crudebyte.com> wrote: > The 9p protocol sends strings in general without null termination > over the wire. However for future use of this functions it is > beneficial for the delivered string to be null terminated though > for being able to use the string with standard C functions which > often rely on strings being null terminated. > > Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com> > --- LGTM Reviewed-by: Greg Kurz <groug@kaod.org> > tests/virtio-9p-test.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/tests/virtio-9p-test.c b/tests/virtio-9p-test.c > index e7b58e3a0c..06263edb53 100644 > --- a/tests/virtio-9p-test.c > +++ b/tests/virtio-9p-test.c > @@ -130,8 +130,9 @@ static void v9fs_string_read(P9Req *req, uint16_t *len, char **string) > *len = local_len; > } > if (string) { > - *string = g_malloc(local_len); > + *string = g_malloc(local_len + 1); > v9fs_memread(req, *string, local_len); > + (*string)[local_len] = 0; > } else { > v9fs_memskip(req, local_len); > }
diff --git a/tests/virtio-9p-test.c b/tests/virtio-9p-test.c index e7b58e3a0c..06263edb53 100644 --- a/tests/virtio-9p-test.c +++ b/tests/virtio-9p-test.c @@ -130,8 +130,9 @@ static void v9fs_string_read(P9Req *req, uint16_t *len, char **string) *len = local_len; } if (string) { - *string = g_malloc(local_len); + *string = g_malloc(local_len + 1); v9fs_memread(req, *string, local_len); + (*string)[local_len] = 0; } else { v9fs_memskip(req, local_len); }
The 9p protocol sends strings in general without null termination over the wire. However for future use of this functions it is beneficial for the delivered string to be null terminated though for being able to use the string with standard C functions which often rely on strings being null terminated. Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com> --- tests/virtio-9p-test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)