Open softrobotYCLi opened 11 months ago
This is a bug in libxo in the assumption about name after a call to memcpy, this patch fixes the issue for me:
diff --git a/libxo/libxo.c b/libxo/libxo.c
index 916a111..ea71723 100644
--- a/libxo/libxo.c
+++ b/libxo/libxo.c
@@ -4300,7 +4300,8 @@ xo_format_value (xo_handle_t *xop, const char *name, ssize_t nlen,
if ((xsp->xs_flags & (XSF_EMIT | XSF_EMIT_KEY))
|| !(xsp->xs_flags & XSF_EMIT_LEAF_LIST)) {
char nbuf[nlen + 1];
- memcpy(nbuf, name, nlen);
+ if (name)
+ memcpy(nbuf, name, nlen);
nbuf[nlen] = '\0';
ssize_t rc = xo_transition(xop, 0, nbuf, XSS_EMIT_LEAF_LIST);
@@ -4324,7 +4325,8 @@ xo_format_value (xo_handle_t *xop, const char *name, ssize_t nlen,
} else if (!(xsp->xs_flags & XSF_EMIT_KEY)) {
char nbuf[nlen + 1];
- memcpy(nbuf, name, nlen);
+ if (name)
+ memcpy(nbuf, name, nlen);
nbuf[nlen] = '\0';
ssize_t rc = xo_transition(xop, 0, nbuf, XSS_EMIT);
@@ -4342,7 +4344,8 @@ xo_format_value (xo_handle_t *xop, const char *name, ssize_t nlen,
if ((xsp->xs_flags & XSF_EMIT_LEAF_LIST)
|| !(xsp->xs_flags & XSF_EMIT)) {
char nbuf[nlen + 1];
- memcpy(nbuf, name, nlen);
+ if (name)
+ memcpy(nbuf, name, nlen);
nbuf[nlen] = '\0';
ssize_t rc = xo_transition(xop, 0, nbuf, XSS_EMIT);
Thank you for your reply, i will check and test the patch.
The problem has been fixed. Who will submit a PR to completely close the problem?
Hi all, i meet a segment fault when compiling libxo with gcc 10. we can use these following commands to reproduce the problem:
env info: