commit: c7e750202c5e17bc8089a8777c4d433b2f63e531 Author: Barnabás Virágh <cyborgyn <AT> gmail <DOT> com> AuthorDate: Sun Oct 3 10:47:50 2021 +0000 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> CommitDate: Sun Oct 3 10:47:50 2021 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=c7e75020
libq/atom: fix atom_clone wrt SUBSLOT A thinko that assumed SUBSLOT was stored in SLOT (which it usually is) caused it to never be copied, since obviously SLOT is terminated, so SUBSLOT, even when originally part of SLOT, would never be contained within SLOT. Just copy it separately, which has the additional bonus of being less obscure. Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> libq/atom.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libq/atom.c b/libq/atom.c index 0959be5..d210ed6 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -373,12 +373,15 @@ atom_clone(depend_atom *atom) size_t plen = 0; size_t nlen = 0; size_t slen = 0; + size_t sslen = 0; size_t rlen = 0; if (atom->REPO != NULL) rlen = strlen(atom->REPO) + 1; if (atom->SLOT != NULL) slen = strlen(atom->SLOT) + 1; + if (atom->SUBSLOT != NULL) + sslen = strlen(atom->SUBSLOT) + 1; if (atom->CATEGORY != NULL) clen = strlen(atom->CATEGORY) + 1; if (atom->PF != NULL) @@ -388,7 +391,7 @@ atom_clone(depend_atom *atom) if (atom->PN != NULL) nlen = strlen(atom->PN) + 1; - alen = sizeof(*ret) + clen + flen + plen + nlen + rlen + slen; + alen = sizeof(*ret) + clen + flen + plen + nlen + rlen + slen + sslen; ret = xmalloc(alen); memset(ret, '\0', sizeof(*ret)); @@ -423,8 +426,11 @@ atom_clone(depend_atom *atom) memcpy(ret->SLOT, atom->SLOT, slen); p += slen; } - if (atom->SUBSLOT > atom->SLOT && atom->SUBSLOT < (atom->SLOT + slen)) - ret->SUBSLOT = ret->SLOT + (atom->SUBSLOT - atom->SLOT); + if (atom->SUBSLOT != NULL) { + ret->SUBSLOT = p; + memcpy(ret->SUBSLOT, atom->SUBSLOT, sslen); + p += sslen; + } if (atom->REPO != NULL) { ret->REPO = p; memcpy(ret->REPO, atom->REPO, rlen);