aboutsummaryrefslogtreecommitdiff
path: root/libctf/ctf-create.c
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2024-01-30 13:40:56 +0000
committerNick Alcock <nick.alcock@oracle.com>2024-04-19 16:14:46 +0100
commit3301ddba1badc50a06f5d21c78790d508969081d (patch)
tree00d35473ebf3d731ba89ece69fe8406696f5b3ba /libctf/ctf-create.c
parent629acbe4a32fc2a53e448ce2c704e788f9fbad9f (diff)
downloadbinutils-3301ddba1badc50a06f5d21c78790d508969081d.zip
binutils-3301ddba1badc50a06f5d21c78790d508969081d.tar.gz
binutils-3301ddba1badc50a06f5d21c78790d508969081d.tar.bz2
Revert "libctf: do not corrupt strings across ctf_serialize"
This reverts commit 986e9e3aa03f854bedacef7fac38fe8f009a416c. (We do not revert the testcase -- it remains valid -- but we are taking a different, less complex and more robust approach.) This also deletes the pending refs abstraction without (yet) replacing it, so some tests will fail for a commit or two.
Diffstat (limited to 'libctf/ctf-create.c')
-rw-r--r--libctf/ctf-create.c27
1 files changed, 3 insertions, 24 deletions
diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c
index 23bbf92..9d86b96 100644
--- a/libctf/ctf-create.c
+++ b/libctf/ctf-create.c
@@ -464,8 +464,7 @@ ctf_add_generic (ctf_dict_t *fp, uint32_t flag, const char *name, int kind,
type = ++fp->ctf_typemax;
type = LCTF_INDEX_TO_TYPE (fp, type, (fp->ctf_flags & LCTF_CHILD));
- dtd->dtd_data.ctt_name = ctf_str_add_pending (fp, name,
- &dtd->dtd_data.ctt_name);
+ dtd->dtd_data.ctt_name = ctf_str_add_ref (fp, name, &dtd->dtd_data.ctt_name);
dtd->dtd_type = type;
if (dtd->dtd_data.ctt_name == 0 && name != NULL && name[0] != '\0')
@@ -1080,21 +1079,11 @@ ctf_add_enumerator (ctf_dict_t *fp, ctf_id_t enid, const char *name,
return -1; /* errno is set for us. */
en = (ctf_enum_t *) dtd->dtd_vlen;
- if (dtd->dtd_vlen != old_vlen)
- {
- ptrdiff_t move = (signed char *) dtd->dtd_vlen - (signed char *) old_vlen;
-
- /* Remove pending refs in the old vlen region and reapply them. */
-
- for (i = 0; i < vlen; i++)
- ctf_str_move_pending (fp, &en[i].cte_name, move);
- }
-
for (i = 0; i < vlen; i++)
if (strcmp (ctf_strptr (fp, en[i].cte_name), name) == 0)
return (ctf_set_errno (ofp, ECTF_DUPLICATE));
- en[i].cte_name = ctf_str_add_pending (fp, name, &en[i].cte_name);
+ en[i].cte_name = ctf_str_add_ref (fp, name, &en[i].cte_name);
en[i].cte_value = value;
if (en[i].cte_name == 0 && name != NULL && name[0] != '\0')
@@ -1154,16 +1143,6 @@ ctf_add_member_offset (ctf_dict_t *fp, ctf_id_t souid, const char *name,
return (ctf_set_errno (ofp, ctf_errno (fp)));
memb = (ctf_lmember_t *) dtd->dtd_vlen;
- if (dtd->dtd_vlen != old_vlen)
- {
- ptrdiff_t move = (signed char *) dtd->dtd_vlen - (signed char *) old_vlen;
-
- /* Remove pending refs in the old vlen region and reapply them. */
-
- for (i = 0; i < vlen; i++)
- ctf_str_move_pending (fp, &memb[i].ctlm_name, move);
- }
-
if (name != NULL)
{
for (i = 0; i < vlen; i++)
@@ -1193,7 +1172,7 @@ ctf_add_member_offset (ctf_dict_t *fp, ctf_id_t souid, const char *name,
return -1; /* errno is set for us. */
}
- memb[vlen].ctlm_name = ctf_str_add_pending (fp, name, &memb[vlen].ctlm_name);
+ memb[vlen].ctlm_name = ctf_str_add_ref (fp, name, &memb[vlen].ctlm_name);
memb[vlen].ctlm_type = type;
if (memb[vlen].ctlm_name == 0 && name != NULL && name[0] != '\0')
return -1; /* errno is set for us. */