public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "Torbjörn SVENSSON" <torbjorn.svensson@foss.st.com>
To: <binutils@sourceware.org>, <nick.alcock@oracle.com>
Cc: amodra@gmail.com,
	"Torbjörn SVENSSON" <torbjorn.svensson@foss.st.com>,
	"Yvan ROUX" <yvan.roux@foss.st.com>
Subject: [PATCH v5] libctf: Sanitize error types for PR 30836
Date: Thu, 5 Oct 2023 10:39:21 +0200	[thread overview]
Message-ID: <20231005083920.2676339-1-torbjorn.svensson@foss.st.com> (raw)
In-Reply-To: <87jzs3l95z.fsf@esperi.org.uk>

v1 -> v2:
Changed all functions with signed interger return type to return -1 based on
comment from Alan.

v2 -> v3:
Added ctf_set_errno_signed function to return a signed -1 value based on
comment from Nick.

v3 -> v4:
- Moved ctf_set_errno_signed function to ctf-inlines.h, renamed it to
ctf_set_int_errno and converted it to an inline function.
- Moved ctf_set_errno function to ctf-inlines.h, renamed it to
ctf_set_type_errno, changed return type to ctf_id_t and converted it to an
inline function.
- Updated the changelog entry in the commit message. Is this list really
required? I don't think it give much information in this patch and 'git log'
have mixed commits (some have the entry while others don't).

v4 -> v5:
Updated in accordance with comments from Nick.
- Changed return type to void for ctf_set_errno.
- Inline the return on every call to ctf_set_errno.
- Merged ctf_set_int_errno and ctf_set_type_errno into ctf_set_errno.
- Droped log entry as it's too many places with this change to make it
  readable.
- Corrected a few places where -1 was returned where it should have been
  CTF_ERR.


@Nick: Can you please try this is in your test bench and let me know if it's
ok for trunk?


--

Made sure there is no implicit conversion between signed and unsigned
return value for functions setting the ctf_errno value.
An example of the problem is that in ctf_member_next, the "offset" value
is either 0L or (ctf_id_t)-1L, but it should have been 0L or -1L.
The issue was discovered while building a 64 bit ld binary to be
executed on the Windows platform.
Example object file that demonstrates the issue is attached in the PR.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
Co-Authored-By: Yvan ROUX <yvan.roux@foss.st.com>
---
 libctf/ctf-create.c    | 321 ++++++++++++++++++++++++++++++++---------
 libctf/ctf-dedup.c     | 130 ++++++++++++-----
 libctf/ctf-dump.c      |  40 +++--
 libctf/ctf-impl.h      |   1 -
 libctf/ctf-inlines.h   |   6 +
 libctf/ctf-labels.c    |  19 ++-
 libctf/ctf-link.c      |  69 +++++++--
 libctf/ctf-lookup.c    |  94 ++++++++----
 libctf/ctf-open.c      |  33 ++++-
 libctf/ctf-serialize.c |  49 +++++--
 libctf/ctf-string.c    |   5 +-
 libctf/ctf-types.c     | 160 +++++++++++++++-----
 libctf/ctf-util.c      |  10 --
 13 files changed, 696 insertions(+), 241 deletions(-)

diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c
index 6b342dc64a2..b3205cd828d 100644
--- a/libctf/ctf-create.c
+++ b/libctf/ctf-create.c
@@ -60,7 +60,10 @@ ctf_grow_ptrtab (ctf_dict_t *fp)
 
       if ((new_ptrtab = realloc (fp->ctf_ptrtab,
 				 new_ptrtab_len * sizeof (uint32_t))) == NULL)
-	return (ctf_set_errno (fp, ENOMEM));
+	{
+	  ctf_set_errno (fp, ENOMEM);
+	  return -1;
+	}
 
       fp->ctf_ptrtab = new_ptrtab;
       memset (fp->ctf_ptrtab + fp->ctf_ptrtab_len, 0,
@@ -87,7 +90,8 @@ ctf_grow_vlen (ctf_dict_t *fp, ctf_dtdef_t *dtd, size_t vlen)
 				dtd->dtd_vlen_alloc * 2)) == NULL)
     {
       dtd->dtd_vlen = old;
-      return (ctf_set_errno (fp, ENOMEM));
+      ctf_set_errno (fp, ENOMEM);
+      return -1;
     }
   memset (dtd->dtd_vlen + dtd->dtd_vlen_alloc, 0, dtd->dtd_vlen_alloc);
   dtd->dtd_vlen_alloc *= 2;
@@ -197,7 +201,10 @@ int
 ctf_update (ctf_dict_t *fp)
 {
   if (!(fp->ctf_flags & LCTF_RDWR))
-    return (ctf_set_errno (fp, ECTF_RDONLY));
+    {
+      ctf_set_errno (fp, ECTF_RDONLY);
+      return -1;
+    }
 
   fp->ctf_dtoldid = fp->ctf_typemax;
   return 0;
@@ -391,10 +398,16 @@ ctf_rollback (ctf_dict_t *fp, ctf_snapshot_id_t id)
   ctf_dvdef_t *dvd, *nvd;
 
   if (!(fp->ctf_flags & LCTF_RDWR))
-    return (ctf_set_errno (fp, ECTF_RDONLY));
+    {
+      ctf_set_errno (fp, ECTF_RDONLY);
+      return -1;
+    }
 
   if (fp->ctf_snapshot_lu >= id.snapshot_id)
-    return (ctf_set_errno (fp, ECTF_OVERROLLBACK));
+    {
+      ctf_set_errno (fp, ECTF_OVERROLLBACK);
+      return -1;
+    }
 
   for (dtd = ctf_list_next (&fp->ctf_dtdefs); dtd != NULL; dtd = ntd)
     {
@@ -453,23 +466,38 @@ ctf_add_generic (ctf_dict_t *fp, uint32_t flag, const char *name, int kind,
   ctf_id_t type;
 
   if (flag != CTF_ADD_NONROOT && flag != CTF_ADD_ROOT)
-    return (ctf_set_errno (fp, EINVAL));
+    {
+      ctf_set_errno (fp, EINVAL);
+      return CTF_ERR;
+    }
 
   if (!(fp->ctf_flags & LCTF_RDWR))
-    return (ctf_set_errno (fp, ECTF_RDONLY));
+    {
+      ctf_set_errno (fp, ECTF_RDONLY);
+      return CTF_ERR;
+    }
 
   if (LCTF_INDEX_TO_TYPE (fp, fp->ctf_typemax, 1) >= CTF_MAX_TYPE)
-    return (ctf_set_errno (fp, ECTF_FULL));
+    {
+      ctf_set_errno (fp, ECTF_FULL);
+      return CTF_ERR;
+    }
 
   if (LCTF_INDEX_TO_TYPE (fp, fp->ctf_typemax, 1) == (CTF_MAX_PTYPE - 1))
-    return (ctf_set_errno (fp, ECTF_FULL));
+    {
+      ctf_set_errno (fp, ECTF_FULL);
+      return CTF_ERR;
+    }
 
   /* Make sure ptrtab always grows to be big enough for all types.  */
   if (ctf_grow_ptrtab (fp) < 0)
       return CTF_ERR;				/* errno is set for us. */
 
   if ((dtd = calloc (1, sizeof (ctf_dtdef_t))) == NULL)
-    return (ctf_set_errno (fp, EAGAIN));
+    {
+      ctf_set_errno (fp, EAGAIN);
+      return CTF_ERR;
+    }
 
   dtd->dtd_vlen_alloc = vlen;
   if (vlen > 0)
@@ -532,13 +560,19 @@ ctf_add_encoded (ctf_dict_t *fp, uint32_t flag,
   uint32_t encoding;
 
   if (ep == NULL)
-    return (ctf_set_errno (fp, EINVAL));
+    {
+      ctf_set_errno (fp, EINVAL);
+      return CTF_ERR;
+    }
 
   if (name == NULL || name[0] == '\0')
-    return (ctf_set_errno (fp, ECTF_NONAME));
+    {
+      ctf_set_errno (fp, ECTF_NONAME);
+      return CTF_ERR;
+    }
 
   if (!ctf_assert (fp, kind == CTF_K_INTEGER || kind == CTF_K_FLOAT))
-    return -1;					/* errno is set for us.  */
+    return CTF_ERR;					/* errno is set for us.  */
 
   if ((type = ctf_add_generic (fp, flag, name, kind, sizeof (uint32_t),
 			       &dtd)) == CTF_ERR)
@@ -570,7 +604,10 @@ ctf_add_reftype (ctf_dict_t *fp, uint32_t flag, ctf_id_t ref, uint32_t kind)
   int child = fp->ctf_flags & LCTF_CHILD;
 
   if (ref == CTF_ERR || ref > CTF_MAX_TYPE)
-    return (ctf_set_errno (fp, EINVAL));
+    {
+      ctf_set_errno (fp, EINVAL);
+      return CTF_ERR;
+    }
 
   if (ref != 0 && ctf_lookup_by_id (&tmp, ref) == NULL)
     return CTF_ERR;		/* errno is set for us.  */
@@ -613,13 +650,22 @@ ctf_add_slice (ctf_dict_t *fp, uint32_t flag, ctf_id_t ref,
   ctf_dict_t *tmp = fp;
 
   if (ep == NULL)
-    return (ctf_set_errno (fp, EINVAL));
+    {
+      ctf_set_errno (fp, EINVAL);
+      return CTF_ERR;
+    }
 
   if ((ep->cte_bits > 255) || (ep->cte_offset > 255))
-    return (ctf_set_errno (fp, ECTF_SLICEOVERFLOW));
+    {
+      ctf_set_errno (fp, ECTF_SLICEOVERFLOW);
+      return CTF_ERR;
+    }
 
   if (ref == CTF_ERR || ref > CTF_MAX_TYPE)
-    return (ctf_set_errno (fp, EINVAL));
+    {
+      ctf_set_errno (fp, EINVAL);
+      return CTF_ERR;
+    }
 
   if (ref != 0 && ((tp = ctf_lookup_by_id (&tmp, ref)) == NULL))
     return CTF_ERR;		/* errno is set for us.  */
@@ -634,7 +680,10 @@ ctf_add_slice (ctf_dict_t *fp, uint32_t flag, ctf_id_t ref,
   if ((kind != CTF_K_INTEGER) && (kind != CTF_K_FLOAT) &&
       (kind != CTF_K_ENUM)
       && (ref != 0))
-    return (ctf_set_errno (fp, ECTF_NOTINTFP));
+    {
+      ctf_set_errno (fp, ECTF_NOTINTFP);
+      return CTF_ERR;
+    }
 
   if ((type = ctf_add_generic (fp, flag, NULL, CTF_K_SLICE,
 			       sizeof (ctf_slice_t), &dtd)) == CTF_ERR)
@@ -682,7 +731,10 @@ ctf_add_array (ctf_dict_t *fp, uint32_t flag, const ctf_arinfo_t *arp)
   ctf_dict_t *tmp = fp;
 
   if (arp == NULL)
-    return (ctf_set_errno (fp, EINVAL));
+    {
+      ctf_set_errno (fp, EINVAL);
+      return CTF_ERR;
+    }
 
   if (arp->ctr_contents != 0
       && ctf_lookup_by_id (&tmp, arp->ctr_contents) == NULL)
@@ -697,7 +749,8 @@ ctf_add_array (ctf_dict_t *fp, uint32_t flag, const ctf_arinfo_t *arp)
       ctf_err_warn (fp, 1, ECTF_INCOMPLETE,
 		    _("ctf_add_array: index type %lx is incomplete"),
 		    arp->ctr_contents);
-      return (ctf_set_errno (fp, ECTF_INCOMPLETE));
+      ctf_set_errno (fp, ECTF_INCOMPLETE);
+      return CTF_ERR;
     }
 
   if ((type = ctf_add_generic (fp, flag, NULL, CTF_K_ARRAY,
@@ -723,11 +776,17 @@ ctf_set_array (ctf_dict_t *fp, ctf_id_t type, const ctf_arinfo_t *arp)
   ctf_array_t *vlen;
 
   if (!(fp->ctf_flags & LCTF_RDWR))
-    return (ctf_set_errno (fp, ECTF_RDONLY));
+    {
+      ctf_set_errno (fp, ECTF_RDONLY);
+      return -1;
+    }
 
   if (dtd == NULL
       || LCTF_INFO_KIND (fp, dtd->dtd_data.ctt_info) != CTF_K_ARRAY)
-    return (ctf_set_errno (fp, ECTF_BADID));
+    {
+      ctf_set_errno (fp, ECTF_BADID);
+      return -1;
+    }
 
   vlen = (ctf_array_t *) dtd->dtd_vlen;
   fp->ctf_flags |= LCTF_DIRTY;
@@ -751,11 +810,17 @@ ctf_add_function (ctf_dict_t *fp, uint32_t flag,
   size_t i;
 
   if (!(fp->ctf_flags & LCTF_RDWR))
-    return (ctf_set_errno (fp, ECTF_RDONLY));
+    {
+      ctf_set_errno (fp, ECTF_RDONLY);
+      return CTF_ERR;
+    }
 
   if (ctc == NULL || (ctc->ctc_flags & ~CTF_FUNC_VARARG) != 0
       || (ctc->ctc_argc != 0 && argv == NULL))
-    return (ctf_set_errno (fp, EINVAL));
+    {
+      ctf_set_errno (fp, EINVAL);
+      return CTF_ERR;
+    }
 
   vlen = ctc->ctc_argc;
   if (ctc->ctc_flags & CTF_FUNC_VARARG)
@@ -766,7 +831,10 @@ ctf_add_function (ctf_dict_t *fp, uint32_t flag,
     return CTF_ERR;				/* errno is set for us.  */
 
   if (vlen > CTF_MAX_VLEN)
-    return (ctf_set_errno (fp, EOVERFLOW));
+    {
+      ctf_set_errno (fp, EOVERFLOW);
+      return CTF_ERR;
+    }
 
   /* One word extra allocated for padding for 4-byte alignment if need be.
      Not reflected in vlen: we don't want to copy anything into it, and
@@ -818,7 +886,10 @@ ctf_add_struct_sized (ctf_dict_t *fp, uint32_t flag, const char *name,
   if (dtd->dtd_vlen_alloc == 0)
     {
       if ((dtd->dtd_vlen = calloc (1, initial_vlen)) == NULL)
-	return (ctf_set_errno (fp, ENOMEM));
+	{
+	  ctf_set_errno (fp, ENOMEM);
+	  return CTF_ERR;
+	}
       dtd->dtd_vlen_alloc = initial_vlen;
     }
 
@@ -858,7 +929,10 @@ ctf_add_union_sized (ctf_dict_t *fp, uint32_t flag, const char *name,
   if (dtd->dtd_vlen_alloc == 0)
     {
       if ((dtd->dtd_vlen = calloc (1, initial_vlen)) == NULL)
-	return (ctf_set_errno (fp, ENOMEM));
+	{
+	  ctf_set_errno (fp, ENOMEM);
+	  return CTF_ERR;
+	}
       dtd->dtd_vlen_alloc = initial_vlen;
     }
 
@@ -897,7 +971,10 @@ ctf_add_enum (ctf_dict_t *fp, uint32_t flag, const char *name)
   if (dtd->dtd_vlen_alloc == 0)
     {
       if ((dtd->dtd_vlen = calloc (1, initial_vlen)) == NULL)
-	return (ctf_set_errno (fp, ENOMEM));
+	{
+	  ctf_set_errno (fp, ENOMEM);
+	  return CTF_ERR;
+	}
       dtd->dtd_vlen_alloc = initial_vlen;
     }
 
@@ -925,7 +1002,10 @@ ctf_add_enum_encoded (ctf_dict_t *fp, uint32_t flag, const char *name,
     {
       if ((ctf_type_kind (fp, type) != CTF_K_FORWARD) &&
 	  (ctf_type_kind_unsliced (fp, type) != CTF_K_ENUM))
-	return (ctf_set_errno (fp, ECTF_NOTINTFP));
+	{
+	  ctf_set_errno (fp, ECTF_NOTINTFP);
+	  return CTF_ERR;
+	}
     }
   else if ((type = ctf_add_enum (fp, flag, name)) == CTF_ERR)
     return CTF_ERR;		/* errno is set for us.  */
@@ -943,10 +1023,16 @@ ctf_add_forward (ctf_dict_t *fp, uint32_t flag, const char *name,
   ctf_id_t type = 0;
 
   if (!ctf_forwardable_kind (kind))
-    return (ctf_set_errno (fp, ECTF_NOTSUE));
+    {
+      ctf_set_errno (fp, ECTF_NOTSUE);
+      return CTF_ERR;
+    }
 
   if (name == NULL || name[0] == '\0')
-    return (ctf_set_errno (fp, ECTF_NONAME));
+    {
+      ctf_set_errno (fp, ECTF_NONAME);
+      return CTF_ERR;
+    }
 
   /* If the type is already defined or exists as a forward tag, just
      return the ctf_id_t of the existing definition.  */
@@ -985,7 +1071,8 @@ ctf_add_unknown (ctf_dict_t *fp, uint32_t flag, const char *name)
 			_("ctf_add_unknown: cannot add unknown type "
 			  "named %s: type of this name already defined"),
 			name ? name : _("(unnamed type)"));
-	  return (ctf_set_errno (fp, ECTF_CONFLICT));
+	  ctf_set_errno (fp, ECTF_CONFLICT);
+	  return CTF_ERR;
 	}
     }
 
@@ -1007,10 +1094,16 @@ ctf_add_typedef (ctf_dict_t *fp, uint32_t flag, const char *name,
   ctf_dict_t *tmp = fp;
 
   if (ref == CTF_ERR || ref > CTF_MAX_TYPE)
-    return (ctf_set_errno (fp, EINVAL));
+    {
+      ctf_set_errno (fp, EINVAL);
+      return CTF_ERR;
+    }
 
   if (name == NULL || name[0] == '\0')
-    return (ctf_set_errno (fp, ECTF_NONAME));
+    {
+      ctf_set_errno (fp, ECTF_NONAME);
+      return CTF_ERR;
+    }
 
   if (ref != 0 && ctf_lookup_by_id (&tmp, ref) == NULL)
     return CTF_ERR;		/* errno is set for us.  */
@@ -1055,23 +1148,38 @@ ctf_add_enumerator (ctf_dict_t *fp, ctf_id_t enid, const char *name,
   uint32_t kind, vlen, root;
 
   if (name == NULL)
-    return (ctf_set_errno (fp, EINVAL));
+    {
+      ctf_set_errno (fp, EINVAL);
+      return -1;
+    }
 
   if (!(fp->ctf_flags & LCTF_RDWR))
-    return (ctf_set_errno (fp, ECTF_RDONLY));
+    {
+      ctf_set_errno (fp, ECTF_RDONLY);
+      return -1;
+    }
 
   if (dtd == NULL)
-    return (ctf_set_errno (fp, ECTF_BADID));
+    {
+      ctf_set_errno (fp, ECTF_BADID);
+      return -1;
+    }
 
   kind = LCTF_INFO_KIND (fp, dtd->dtd_data.ctt_info);
   root = LCTF_INFO_ISROOT (fp, dtd->dtd_data.ctt_info);
   vlen = LCTF_INFO_VLEN (fp, dtd->dtd_data.ctt_info);
 
   if (kind != CTF_K_ENUM)
-    return (ctf_set_errno (fp, ECTF_NOTENUM));
+    {
+      ctf_set_errno (fp, ECTF_NOTENUM);
+      return -1;
+    }
 
   if (vlen == CTF_MAX_VLEN)
-    return (ctf_set_errno (fp, ECTF_DTFULL));
+    {
+      ctf_set_errno (fp, ECTF_DTFULL);
+      return -1;
+    }
 
   old_vlen = dtd->dtd_vlen;
   if (ctf_grow_vlen (fp, dtd, sizeof (ctf_enum_t) * (vlen + 1)) < 0)
@@ -1090,7 +1198,10 @@ ctf_add_enumerator (ctf_dict_t *fp, ctf_id_t enid, const char *name,
 
   for (i = 0; i < vlen; i++)
     if (strcmp (ctf_strptr (fp, en[i].cte_name), name) == 0)
-      return (ctf_set_errno (fp, ECTF_DUPLICATE));
+      {
+	ctf_set_errno (fp, ECTF_DUPLICATE);
+	return -1;
+      }
 
   en[i].cte_name = ctf_str_add_pending (fp, name, &en[i].cte_name);
   en[i].cte_value = value;
@@ -1119,10 +1230,16 @@ ctf_add_member_offset (ctf_dict_t *fp, ctf_id_t souid, const char *name,
   ctf_lmember_t *memb;
 
   if (!(fp->ctf_flags & LCTF_RDWR))
-    return (ctf_set_errno (fp, ECTF_RDONLY));
+    {
+      ctf_set_errno (fp, ECTF_RDONLY);
+      return -1;
+    }
 
   if (dtd == NULL)
-    return (ctf_set_errno (fp, ECTF_BADID));
+    {
+      ctf_set_errno (fp, ECTF_BADID);
+      return -1;
+    }
 
   if (name != NULL && name[0] == '\0')
     name = NULL;
@@ -1132,10 +1249,16 @@ ctf_add_member_offset (ctf_dict_t *fp, ctf_id_t souid, const char *name,
   vlen = LCTF_INFO_VLEN (fp, dtd->dtd_data.ctt_info);
 
   if (kind != CTF_K_STRUCT && kind != CTF_K_UNION)
-    return (ctf_set_errno (fp, ECTF_NOTSOU));
+    {
+      ctf_set_errno (fp, ECTF_NOTSOU);
+      return -1;
+    }
 
   if (vlen == CTF_MAX_VLEN)
-    return (ctf_set_errno (fp, ECTF_DTFULL));
+    {
+      ctf_set_errno (fp, ECTF_DTFULL);
+      return -1;
+    }
 
   old_vlen = dtd->dtd_vlen;
   if (ctf_grow_vlen (fp, dtd, sizeof (ctf_lmember_t) * (vlen + 1)) < 0)
@@ -1156,7 +1279,10 @@ ctf_add_member_offset (ctf_dict_t *fp, ctf_id_t souid, const char *name,
     {
       for (i = 0; i < vlen; i++)
 	if (strcmp (ctf_strptr (fp, memb[i].ctlm_name), name) == 0)
-	  return (ctf_set_errno (fp, ECTF_DUPLICATE));
+	  {
+	    ctf_set_errno (fp, ECTF_DUPLICATE);
+	    return -1;
+	  }
     }
 
   if ((msize = ctf_type_size (fp, type)) < 0 ||
@@ -1212,7 +1338,8 @@ ctf_add_member_offset (ctf_dict_t *fp, ctf_id_t souid, const char *name,
 			      "incomplete type %lx to struct %lx without "
 			      "specifying explicit offset\n"),
 			    name ? name : _("(unnamed member)"), type, souid);
-	      return (ctf_set_errno (fp, ECTF_INCOMPLETE));
+	      ctf_set_errno (fp, ECTF_INCOMPLETE);
+	      return -1;
 	    }
 
 	  if (ctf_type_encoding (fp, ltype, &linfo) == 0)
@@ -1285,7 +1412,10 @@ ctf_add_member_encoded (ctf_dict_t *fp, ctf_id_t souid, const char *name,
   int otype = type;
 
   if ((kind != CTF_K_INTEGER) && (kind != CTF_K_FLOAT) && (kind != CTF_K_ENUM))
-    return (ctf_set_errno (fp, ECTF_NOTINTFP));
+    {
+      ctf_set_errno (fp, ECTF_NOTINTFP);
+      return -1;
+    }
 
   if ((type = ctf_add_slice (fp, CTF_ADD_NONROOT, otype, &encoding)) == CTF_ERR)
     return -1;			/* errno is set for us.  */
@@ -1307,10 +1437,16 @@ ctf_add_variable (ctf_dict_t *fp, const char *name, ctf_id_t ref)
   ctf_dict_t *tmp = fp;
 
   if (!(fp->ctf_flags & LCTF_RDWR))
-    return (ctf_set_errno (fp, ECTF_RDONLY));
+    {
+      ctf_set_errno (fp, ECTF_RDONLY);
+      return -1;
+    }
 
   if (ctf_dvd_lookup (fp, name) != NULL)
-    return (ctf_set_errno (fp, ECTF_DUPLICATE));
+    {
+      ctf_set_errno (fp, ECTF_DUPLICATE);
+      return -1;
+    }
 
   if (ctf_lookup_by_id (&tmp, ref) == NULL)
     return -1;			/* errno is set for us.  */
@@ -1321,12 +1457,16 @@ ctf_add_variable (ctf_dict_t *fp, const char *name, ctf_id_t ref)
     return -1;
 
   if ((dvd = malloc (sizeof (ctf_dvdef_t))) == NULL)
-    return (ctf_set_errno (fp, EAGAIN));
+    {
+      ctf_set_errno (fp, EAGAIN);
+      return -1;
+    }
 
   if (name != NULL && (dvd->dvd_name = strdup (name)) == NULL)
     {
       free (dvd);
-      return (ctf_set_errno (fp, EAGAIN));
+      ctf_set_errno (fp, EAGAIN);
+      return -1;
     }
   dvd->dvd_type = ref;
   dvd->dvd_snapshots = fp->ctf_snapshots;
@@ -1350,25 +1490,38 @@ ctf_add_funcobjt_sym (ctf_dict_t *fp, int is_function, const char *name, ctf_id_
   ctf_dynhash_t *h = is_function ? fp->ctf_funchash : fp->ctf_objthash;
 
   if (!(fp->ctf_flags & LCTF_RDWR))
-    return (ctf_set_errno (fp, ECTF_RDONLY));
+    {
+      ctf_set_errno (fp, ECTF_RDONLY);
+      return -1;
+    }
 
   if (ctf_dynhash_lookup (fp->ctf_objthash, name) != NULL ||
       ctf_dynhash_lookup (fp->ctf_funchash, name) != NULL)
-    return (ctf_set_errno (fp, ECTF_DUPLICATE));
+    {
+      ctf_set_errno (fp, ECTF_DUPLICATE);
+      return -1;
+    }
 
   if (ctf_lookup_by_id (&tmp, id) == NULL)
     return -1;                                  /* errno is set for us.  */
 
   if (is_function && ctf_type_kind (fp, id) != CTF_K_FUNCTION)
-    return (ctf_set_errno (fp, ECTF_NOTFUNC));
+    {
+      ctf_set_errno (fp, ECTF_NOTFUNC);
+      return -1;
+    }
 
   if ((dupname = strdup (name)) == NULL)
-    return (ctf_set_errno (fp, ENOMEM));
+    {
+      ctf_set_errno (fp, ENOMEM);
+      return -1;
+    }
 
   if (ctf_dynhash_insert (h, dupname, (void *) (uintptr_t) id) < 0)
     {
       free (dupname);
-      return (ctf_set_errno (fp, ENOMEM));
+      ctf_set_errno (fp, ENOMEM);
+      return -1;
     }
   return 0;
 }
@@ -1575,14 +1728,23 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
   ctf_id_t orig_src_type = src_type;
 
   if (!(dst_fp->ctf_flags & LCTF_RDWR))
-    return (ctf_set_errno (dst_fp, ECTF_RDONLY));
+    {
+      ctf_set_errno (dst_fp, ECTF_RDONLY);
+      return CTF_ERR;
+    }
 
   if ((src_tp = ctf_lookup_by_id (&src_fp, src_type)) == NULL)
-    return (ctf_set_errno (dst_fp, ctf_errno (src_fp)));
+    {
+      ctf_set_errno (dst_fp, ctf_errno (src_fp));
+      return CTF_ERR;
+    }
 
   if ((ctf_type_resolve (src_fp, src_type) == CTF_ERR)
       && (ctf_errno (src_fp) == ECTF_NONREPRESENTABLE))
-    return (ctf_set_errno (dst_fp, ECTF_NONREPRESENTABLE));
+    {
+      ctf_set_errno (dst_fp, ECTF_NONREPRESENTABLE);
+      return CTF_ERR;
+    }
 
   name = ctf_strptr (src_fp, src_tp->ctt_name);
   kind = LCTF_INFO_KIND (src_fp, src_tp->ctt_info);
@@ -1661,7 +1823,8 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
 			_("ctf_add_type: conflict for type %s: "
 			  "kinds differ, new: %i; old (ID %lx): %i"),
 			name, kind, dst_type, dst_kind);
-	  return (ctf_set_errno (dst_fp, ECTF_CONFLICT));
+	  ctf_set_errno (dst_fp, ECTF_CONFLICT);
+	  return CTF_ERR;
 	}
     }
 
@@ -1672,7 +1835,10 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
   if (kind == CTF_K_INTEGER || kind == CTF_K_FLOAT || kind == CTF_K_SLICE)
     {
       if (ctf_type_encoding (src_fp, src_type, &src_en) != 0)
-	return (ctf_set_errno (dst_fp, ctf_errno (src_fp)));
+	{
+	  ctf_set_errno (dst_fp, ctf_errno (src_fp));
+	  return CTF_ERR;
+	}
 
       if (dst_type != CTF_ERR)
 	{
@@ -1702,7 +1868,8 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
 		}
 	      else
 		  {
-		    return (ctf_set_errno (dst_fp, ECTF_CONFLICT));
+		    ctf_set_errno (dst_fp, ECTF_CONFLICT);
+		    return CTF_ERR;
 		  }
 	    }
 	  else
@@ -1740,7 +1907,10 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
 
   if (ctf_dynhash_insert (proc_tracking_fp->ctf_add_processing,
 			  (void *) (uintptr_t) src_type, (void *) 1) < 0)
-    return ctf_set_errno (dst_fp, ENOMEM);
+    {
+      ctf_set_errno (dst_fp, ENOMEM);
+      return CTF_ERR;
+    }
 
   switch (kind)
     {
@@ -1785,7 +1955,10 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
 
     case CTF_K_ARRAY:
       if (ctf_array_info (src_fp, src_type, &src_ar) != 0)
-	return (ctf_set_errno (dst_fp, ctf_errno (src_fp)));
+	{
+	  ctf_set_errno (dst_fp, ctf_errno (src_fp));
+	  return CTF_ERR;
+	}
 
       src_ar.ctr_contents =
 	ctf_add_type_internal (dst_fp, src_fp, src_ar.ctr_contents,
@@ -1812,7 +1985,8 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
 			    src_ar.ctr_index, src_ar.ctr_nelems,
 			    dst_ar.ctr_contents, dst_ar.ctr_index,
 			    dst_ar.ctr_nelems);
-	      return (ctf_set_errno (dst_fp, ECTF_CONFLICT));
+	      ctf_set_errno (dst_fp, ECTF_CONFLICT);
+	      return CTF_ERR;
 	    }
 	}
       else
@@ -1859,7 +2033,8 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
 				"size differs, old %li, new %li"), name,
 			      dst_type, (long) ctf_type_size (src_fp, src_type),
 			      (long) ctf_type_size (dst_fp, dst_type));
-		return (ctf_set_errno (dst_fp, ECTF_CONFLICT));
+		ctf_set_errno (dst_fp, ECTF_CONFLICT);
+		return CTF_ERR;
 	      }
 
 	    if (ctf_member_iter (src_fp, src_type, membcmp, &dst))
@@ -1867,7 +2042,8 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
 		ctf_err_warn (dst_fp, 1, ECTF_CONFLICT,
 			      _("conflict for type %s against ID %lx: members "
 				"differ, see above"), name, dst_type);
-		return (ctf_set_errno (dst_fp, ECTF_CONFLICT));
+		ctf_set_errno (dst_fp, ECTF_CONFLICT);
+		return CTF_ERR;
 	      }
 
 	    break;
@@ -1925,7 +2101,8 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
 	      ctf_err_warn (dst_fp, 1, ECTF_CONFLICT,
 			    _("conflict for enum %s against ID %lx: members "
 			      "differ, see above"), name, dst_type);
-	      return (ctf_set_errno (dst_fp, ECTF_CONFLICT));
+	      ctf_set_errno (dst_fp, ECTF_CONFLICT);
+	      return CTF_ERR;
 	    }
 	}
       else
@@ -1964,7 +2141,8 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
       break;
 
     default:
-      return (ctf_set_errno (dst_fp, ECTF_CORRUPT));
+      ctf_set_errno (dst_fp, ECTF_CORRUPT);
+      return CTF_ERR;
     }
 
   if (dst_type != CTF_ERR)
@@ -1985,7 +2163,10 @@ ctf_add_type (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type)
   /* We store the hash on the source, because it contains only source type IDs:
      but callers will invariably expect errors to appear on the dest.  */
   if (!src_fp->ctf_add_processing)
-    return (ctf_set_errno (dst_fp, ENOMEM));
+    {
+      ctf_set_errno (dst_fp, ENOMEM);
+      return CTF_ERR;
+    }
 
   id = ctf_add_type_internal (dst_fp, src_fp, src_type, src_fp);
   ctf_dynhash_empty (src_fp->ctf_add_processing);
diff --git a/libctf/ctf-dedup.c b/libctf/ctf-dedup.c
index 5fdddfd0b54..d4f198ccb21 100644
--- a/libctf/ctf-dedup.c
+++ b/libctf/ctf-dedup.c
@@ -378,7 +378,10 @@ ctf_dedup_atoms_init (ctf_dict_t *fp)
       if ((fp->ctf_dedup_atoms_alloc
 	   = ctf_dynset_create (htab_hash_string, htab_eq_string,
 				free)) == NULL)
-	return ctf_set_errno (fp, ENOMEM);
+	{
+	  ctf_set_errno (fp, ENOMEM);
+	  return -1;
+	}
     }
   fp->ctf_dedup_atoms = fp->ctf_dedup_atoms_alloc;
   return 0;
@@ -543,7 +546,10 @@ ctf_dedup_record_origin (ctf_dict_t *fp, int input_num, const char *decorated,
 
   if (populate_origin)
     if (ctf_dynhash_cinsert (d->cd_struct_origin, decorated, origin) < 0)
-      return ctf_set_errno (fp, errno);
+      {
+	ctf_set_errno (fp, errno);
+	return -1;
+      }
   return 0;
 }
 
@@ -1185,7 +1191,10 @@ ctf_dedup_populate_mappings (ctf_dict_t *fp, ctf_dict_t *input _libctf_unused_,
     }
   else
     if (ctf_dynhash_cinsert (d->cd_output_mapping_guard, id, hval) < 0)
-      return ctf_set_errno (fp, errno);
+      {
+	ctf_set_errno (fp, errno);
+	return -1;
+      }
 #endif
 
   /* Record the type in the output mapping: if this is the first time this type
@@ -1197,17 +1206,24 @@ ctf_dedup_populate_mappings (ctf_dict_t *fp, ctf_dict_t *input _libctf_unused_,
 				      hval)) == NULL)
     {
       if (ctf_dynhash_cinsert (d->cd_output_first_gid, hval, id) < 0)
-	return ctf_set_errno (fp, errno);
+	{
+	  ctf_set_errno (fp, errno);
+	  return -1;
+	}
 
       if ((type_ids = ctf_dynset_create (htab_hash_pointer,
 					 htab_eq_pointer,
 					 NULL)) == NULL)
-	return ctf_set_errno (fp, errno);
+	{
+	  ctf_set_errno (fp, errno);
+	  return -1;
+	}
       if (ctf_dynhash_insert (d->cd_output_mapping, (void *) hval,
 			      type_ids) < 0)
 	{
 	  ctf_dynset_destroy (type_ids);
-	  return ctf_set_errno (fp, errno);
+	  ctf_set_errno (fp, errno);
+	  return -1;
 	}
     }
 #ifdef ENABLE_LIBCTF_HASH_DEBUGGING
@@ -1248,7 +1264,10 @@ ctf_dedup_populate_mappings (ctf_dict_t *fp, ctf_dict_t *input _libctf_unused_,
 	    }
 	}
       if (err != ECTF_NEXT_END)
-	return ctf_set_errno (fp, err);
+	{
+	  ctf_set_errno (fp, err);
+	  return -1;
+	}
     }
 #endif
 
@@ -1256,7 +1275,10 @@ ctf_dedup_populate_mappings (ctf_dict_t *fp, ctf_dict_t *input _libctf_unused_,
      don't waste time reinserting the same keys in that case.  */
   if (!ctf_dynset_exists (type_ids, id, NULL)
       && ctf_dynset_insert (type_ids, id) < 0)
-    return ctf_set_errno (fp, errno);
+    {
+      ctf_set_errno (fp, errno);
+      return -1;
+    }
 
   /* The rest only needs to happen for types with names.  */
   if (!decorated_name)
@@ -1273,12 +1295,16 @@ ctf_dedup_populate_mappings (ctf_dict_t *fp, ctf_dict_t *input _libctf_unused_,
       if ((name_counts = ctf_dynhash_create (ctf_hash_string,
 					     ctf_hash_eq_string,
 					     NULL, NULL)) == NULL)
-	  return ctf_set_errno (fp, errno);
+	{
+	  ctf_set_errno (fp, errno);
+	  return -1;
+	}
       if (ctf_dynhash_cinsert (d->cd_name_counts, decorated_name,
 			       name_counts) < 0)
 	{
 	  ctf_dynhash_destroy (name_counts);
-	  return ctf_set_errno (fp, errno);
+	  ctf_set_errno (fp, errno);
+	  return -1;
 	}
     }
 
@@ -1287,7 +1313,10 @@ ctf_dedup_populate_mappings (ctf_dict_t *fp, ctf_dict_t *input _libctf_unused_,
 
   if (ctf_dynhash_cinsert (name_counts, hval,
 			   (const void *) (uintptr_t) (count + 1)) < 0)
-    return ctf_set_errno (fp, errno);
+    {
+      ctf_set_errno (fp, errno);
+      return -1;
+    }
 
   return 0;
 }
@@ -1339,10 +1368,11 @@ ctf_dedup_mark_conflicting_hash (ctf_dict_t *fp, const char *hval)
 	  return -1;				/* errno is set for us.  */
 	}
     }
-  if (err != ECTF_NEXT_END)
-    return ctf_set_errno (fp, err);
+  if (err == ECTF_NEXT_END)
+    return 0;
 
-  return 0;
+  ctf_set_errno (fp, err);
+  return -1;
 }
 
 /* Look up a type kind from the output mapping, given a type hash value.  */
@@ -1366,7 +1396,8 @@ ctf_dedup_hash_kind (ctf_dict_t *fp, ctf_dict_t **inputs, const char *hash)
   if (!type_ids)
     {
       ctf_dprintf ("Looked up type kind by nonexistent hash %s.\n", hash);
-      return ctf_set_errno (fp, ECTF_INTERNAL);
+      ctf_set_errno (fp, ECTF_INTERNAL);
+      return -1;
     }
   id = ctf_dynset_lookup_any (type_ids);
   if (!ctf_assert (fp, id))
@@ -1585,7 +1616,8 @@ ctf_dedup_detect_name_ambiguity (ctf_dict_t *fp, ctf_dict_t **inputs)
 
  iterr:
   ctf_err_warn (fp, 0, err, _("iteration failed: %s"), gettext (whaterr));
-  return ctf_set_errno (fp, err);
+  ctf_set_errno (fp, err);
+  return -1;
 
  assert_err:
   ctf_next_destroy (i);
@@ -1683,7 +1715,8 @@ ctf_dedup_init (ctf_dict_t *fp)
  oom:
   ctf_err_warn (fp, 0, ENOMEM, _("ctf_dedup_init: cannot initialize: "
 				 "out of memory"));
-  return ctf_set_errno (fp, ENOMEM);
+  ctf_set_errno (fp, ENOMEM);
+  return -1;
 }
 
 /* No ctf_dedup calls are allowed after this call other than starting a new
@@ -1784,7 +1817,8 @@ ctf_dedup_multiple_input_dicts (ctf_dict_t *output, ctf_dict_t **inputs,
     {
       ctf_err_warn (output, 0, err, _("iteration error "
 				      "propagating conflictedness"));
-      return ctf_set_errno (output, err);
+      ctf_set_errno (output, err);
+      return -1;
     }
 
   if (multiple)
@@ -1879,7 +1913,8 @@ ctf_dedup_conflictify_unshared (ctf_dict_t *output, ctf_dict_t **inputs)
  iterr:
   ctf_dynset_destroy (to_mark);
   ctf_err_warn (output, 0, err, _("conflictifying unshared types"));
-  return ctf_set_errno (output, err);
+  ctf_set_errno (output, err);
+  return -1;
 }
 
 /* The core deduplicator.  Populate cd_output_mapping in the output ctf_dedup
@@ -2219,7 +2254,8 @@ ctf_dedup_rwalk_output_mapping (ctf_dict_t *output, ctf_dict_t **inputs,
     {
       ctf_err_warn (output, 0, ECTF_INTERNAL,
 		    _("looked up type kind by nonexistent hash %s"), hval);
-      return ctf_set_errno (output, ECTF_INTERNAL);
+      ctf_set_errno (output, ECTF_INTERNAL);
+      return -1;
     }
 
   /* Have we seen this type before?  */
@@ -2237,7 +2273,8 @@ ctf_dedup_rwalk_output_mapping (ctf_dict_t *output, ctf_dict_t **inputs,
 	{
 	  ctf_err_warn (output, 0, ENOMEM,
 			_("out of memory tracking already-visited types"));
-	  return ctf_set_errno (output, ENOMEM);
+	  ctf_set_errno (output, ENOMEM);
+	  return -1;
 	}
     }
 
@@ -2274,7 +2311,8 @@ ctf_dedup_rwalk_output_mapping (ctf_dict_t *output, ctf_dict_t **inputs,
   if (err != ECTF_NEXT_END)
     {
       ctf_err_warn (output, 0, err, _("cannot walk conflicted type"));
-      return ctf_set_errno (output, err);
+      ctf_set_errno (output, err);
+      return -1;
     }
 
   return 0;
@@ -2376,7 +2414,10 @@ ctf_dedup_walk_output_mapping (ctf_dict_t *output, ctf_dict_t **inputs,
   if ((already_visited = ctf_dynset_create (htab_hash_string,
 					    htab_eq_string,
 					    NULL)) == NULL)
-    return ctf_set_errno (output, ENOMEM);
+    {
+      ctf_set_errno (output, ENOMEM);
+      return -1;
+    }
 
   sort_arg.inputs = inputs;
   sort_arg.ninputs = ninputs;
@@ -2525,7 +2566,7 @@ ctf_dedup_id_to_target (ctf_dict_t *output, ctf_dict_t *target,
   if ((input->ctf_flags & LCTF_CHILD) && (LCTF_TYPE_ISPARENT (input, id)))
     {
       if (!ctf_assert (output, parents[input_num] <= ninputs))
-	return -1;
+	return CTF_ERR;
       input = inputs[parents[input_num]];
       input_num = parents[input_num];
     }
@@ -2534,7 +2575,7 @@ ctf_dedup_id_to_target (ctf_dict_t *output, ctf_dict_t *target,
 			     CTF_DEDUP_GID (output, input_num, id));
 
   if (!ctf_assert (output, hval && td->cd_output_emission_hashes))
-    return -1;
+    return CTF_ERR;
 
   /* If this type is a conflicted tagged structure, union, or forward,
      substitute a synthetic forward instead, emitting it if need be.  Only do
@@ -2553,7 +2594,7 @@ ctf_dedup_id_to_target (ctf_dict_t *output, ctf_dict_t *target,
       ctf_set_errno (err_fp, ctf_errno (output));
       ctf_err_warn (err_fp, 0, 0, _("cannot add synthetic forward for type "
 				    "%i/%lx"), input_num, id);
-      return -1;
+      return CTF_ERR;
     default:
       return emitted_forward;
     }
@@ -2568,7 +2609,7 @@ ctf_dedup_id_to_target (ctf_dict_t *output, ctf_dict_t *target,
       ctf_dprintf ("Checking shared parent for target\n");
       if (!ctf_assert (output, (target != output)
 		       && (target->ctf_flags & LCTF_CHILD)))
-	return -1;
+	return CTF_ERR;
 
       target_id = ctf_dynhash_lookup (od->cd_output_emission_hashes, hval);
 
@@ -2582,13 +2623,14 @@ ctf_dedup_id_to_target (ctf_dict_t *output, ctf_dict_t *target,
 	  ctf_err_warn (err_fp, 0, ctf_errno (output),
 			_("cannot add synthetic forward for type %i/%lx"),
 			input_num, id);
-	  return ctf_set_errno (err_fp, ctf_errno (output));
+	  ctf_set_errno (err_fp, ctf_errno (output));
+	  return CTF_ERR;
 	default:
 	  return emitted_forward;
 	}
     }
   if (!ctf_assert (output, target_id))
-    return -1;
+    return CTF_ERR;
   return (ctf_id_t) (uintptr_t) target_id;
 }
 
@@ -2664,7 +2706,8 @@ ctf_dedup_emit_type (const char *hval, ctf_dict_t *output, ctf_dict_t **inputs,
 	      ctf_err_warn (output, 0, err,
 			    _("cannot create per-CU CTF archive for CU %s"),
 			    ctf_link_input_name (input));
-	      return ctf_set_errno (output, err);
+	      ctf_set_errno (output, err);
+	      return -1;
 	    }
 
 	  ctf_import_unref (target, output);
@@ -2687,7 +2730,8 @@ ctf_dedup_emit_type (const char *hval, ctf_dict_t *output, ctf_dict_t **inputs,
       ctf_err_warn (output, 0, ctf_errno (input),
 		    _("%s: lookup failure for type %lx"),
 		    ctf_link_input_name (real_input), type);
-      return ctf_set_errno (output, ctf_errno (input));
+      ctf_set_errno (output, ctf_errno (input));
+      return -1;
     }
 
   name = ctf_strraw (real_input, tp->ctt_name);
@@ -2765,7 +2809,8 @@ ctf_dedup_emit_type (const char *hval, ctf_dict_t *output, ctf_dict_t **inputs,
 			      ctf_link_input_name (input), input_num, name,
 			      type);
 		ctf_next_destroy (i);
-		return ctf_set_errno (output, ctf_errno (target));
+		ctf_set_errno (output, ctf_errno (target));
+		return -1;
 	      }
 	  }
 	if (ctf_errno (input) != ECTF_NEXT_END)
@@ -2921,7 +2966,8 @@ ctf_dedup_emit_type (const char *hval, ctf_dict_t *output, ctf_dict_t **inputs,
       ctf_err_warn (output, 0, ECTF_CORRUPT, _("%s: unknown type kind for "
 					       "input type %lx"),
 		    ctf_link_input_name (input), type);
-      return ctf_set_errno (output, ECTF_CORRUPT);
+      ctf_set_errno (output, ECTF_CORRUPT);
+      return -1;
     }
 
   if (!emission_hashed
@@ -2931,7 +2977,8 @@ ctf_dedup_emit_type (const char *hval, ctf_dict_t *output, ctf_dict_t **inputs,
     {
       ctf_err_warn (output, 0, ENOMEM, _("out of memory tracking deduplicated "
 					 "global type IDs"));
-	return ctf_set_errno (output, ENOMEM);
+      ctf_set_errno (output, ENOMEM);
+      return -1;
     }
 
   if (!emission_hashed && new_type != 0)
@@ -2944,21 +2991,24 @@ ctf_dedup_emit_type (const char *hval, ctf_dict_t *output, ctf_dict_t **inputs,
  oom_hash:
   ctf_err_warn (output, 0, ENOMEM, _("out of memory creating emission-tracking "
 				     "hashes"));
-  return ctf_set_errno (output, ENOMEM);
+  ctf_set_errno (output, ENOMEM);
+  return -1;
 
  err_input:
   ctf_err_warn (output, 0, ctf_errno (input),
 		_("%s (%i): while emitting deduplicated %s, error getting "
 		  "input type %lx"), ctf_link_input_name (input),
 		input_num, errtype, type);
-  return ctf_set_errno (output, ctf_errno (input));
+  ctf_set_errno (output, ctf_errno (input));
+  return -1;
  err_target:
   ctf_err_warn (output, 0, ctf_errno (target),
 		_("%s (%i): while emitting deduplicated %s, error emitting "
 		  "target type from input type %lx"),
 		ctf_link_input_name (input), input_num,
 		errtype, type);
-  return ctf_set_errno (output, ctf_errno (target));
+  ctf_set_errno (output, ctf_errno (target));
+  return -1;
 }
 
 /* Traverse the cd_emission_struct_members and emit the members of all
@@ -3051,11 +3101,13 @@ ctf_dedup_emit_struct_members (ctf_dict_t *output, ctf_dict_t **inputs,
   ctf_err_warn (output, 0, ctf_errno (err_fp),
 		_("%s (%i): error emitting members for structure type %lx"),
 		ctf_link_input_name (input_fp), input_num, err_type);
-  return ctf_set_errno (output, ctf_errno (err_fp));
+  ctf_set_errno (output, ctf_errno (err_fp));
+  return -1;
  iterr:
   ctf_err_warn (output, 0, err, _("iteration failure emitting "
 				  "structure members"));
-  return ctf_set_errno (output, err);
+  ctf_set_errno (output, err);
+  return -1;
 }
 
 /* Emit deduplicated types into the outputs.  The shared type repository is
diff --git a/libctf/ctf-dump.c b/libctf/ctf-dump.c
index 686951a9869..b5de3c76709 100644
--- a/libctf/ctf-dump.c
+++ b/libctf/ctf-dump.c
@@ -56,7 +56,10 @@ ctf_dump_append (ctf_dump_state_t *state, char *str)
   ctf_dump_item_t *cdi;
 
   if ((cdi = malloc (sizeof (struct ctf_dump_item))) == NULL)
-    return (ctf_set_errno (state->cds_fp, ENOMEM));
+    {
+      ctf_set_errno (state->cds_fp, ENOMEM);
+      return -1;
+    }
 
   cdi->cdi_item = str;
   ctf_list_append (&state->cds_items, cdi);
@@ -261,7 +264,8 @@ ctf_dump_header_strfield (ctf_dict_t *fp, ctf_dump_state_t *state,
   return 0;
 
  err:
-  return (ctf_set_errno (fp, errno));
+  ctf_set_errno (fp, errno);
+  return -1;
 }
 
 /* Dump one section-offset field from the file header into the cds_items.  */
@@ -281,7 +285,8 @@ ctf_dump_header_sectfield (ctf_dict_t *fp, ctf_dump_state_t *state,
   return 0;
 
  err:
-  return (ctf_set_errno (fp, errno));
+  ctf_set_errno (fp, errno);
+  return -1;
 }
 
 /* Dump the file header into the cds_items.  */
@@ -398,7 +403,8 @@ ctf_dump_header (ctf_dict_t *fp, ctf_dump_state_t *state)
   return 0;
  err:
   free (flagstr);
-  return (ctf_set_errno (fp, errno));
+  ctf_set_errno (fp, errno);
+  return -1;
 }
 
 /* Dump a single label into the cds_items.  */
@@ -412,7 +418,10 @@ ctf_dump_label (const char *name, const ctf_lblinfo_t *info,
   ctf_dump_state_t *state = arg;
 
   if (asprintf (&str, "%s -> ", name) < 0)
-    return (ctf_set_errno (state->cds_fp, errno));
+    {
+      ctf_set_errno (state->cds_fp, errno);
+      return -1;
+    }
 
   if ((typestr = ctf_dump_format_type (state->cds_fp, info->ctb_type,
 				       CTF_ADD_ROOT | CTF_FT_REFS)) == NULL)
@@ -487,7 +496,10 @@ ctf_dump_var (const char *name, ctf_id_t type, void *arg)
   ctf_dump_state_t *state = arg;
 
   if (asprintf (&str, "%s -> ", name) < 0)
-    return (ctf_set_errno (state->cds_fp, errno));
+    {
+      ctf_set_errno (state->cds_fp, errno);
+      return -1;
+    }
 
   if ((typestr = ctf_dump_format_type (state->cds_fp, type,
 				       CTF_ADD_ROOT | CTF_FT_REFS)) == NULL)
@@ -540,7 +552,8 @@ ctf_dump_member (const char *name, ctf_id_t id, unsigned long offset,
  oom:
   free (typestr);
   free (bit);
-  return (ctf_set_errno (state->cdm_fp, errno));
+  ctf_set_errno (state->cdm_fp, errno);
+  return -1;
 }
 
 /* Report the number of digits in the hexadecimal representation of a type
@@ -569,7 +582,10 @@ ctf_dump_type (ctf_id_t id, int flag, void *arg)
 
   /* Indent neatly.  */
   if (asprintf (&indent, "    %*s", type_hex_digits (id), "") < 0)
-    return (ctf_set_errno (state->cds_fp, ENOMEM));
+    {
+      ctf_set_errno (state->cds_fp, ENOMEM);
+      return -1;
+    }
 
   /* Dump the type itself.  */
   if ((str = ctf_dump_format_type (state->cds_fp, id,
@@ -654,7 +670,8 @@ ctf_dump_type (ctf_id_t id, int flag, void *arg)
  oom:
   free (indent);
   free (str);
-  return ctf_set_errno (state->cds_fp, ENOMEM);
+  ctf_set_errno (state->cds_fp, ENOMEM);
+  return -1;
 }
 
 /* Dump the string table into the cds_items.  */
@@ -671,7 +688,10 @@ ctf_dump_str (ctf_dict_t *fp, ctf_dump_state_t *state)
       if (asprintf (&str, "0x%lx: %s",
 		    (unsigned long) (s - fp->ctf_str[CTF_STRTAB_0].cts_strs),
 		    s) < 0)
-	return (ctf_set_errno (fp, errno));
+	{
+	  ctf_set_errno (fp, errno);
+	  return -1;
+	}
       ctf_dump_append (state, str);
       s += strlen (s) + 1;
     }
diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h
index da687762c89..77d74ef0ea9 100644
--- a/libctf/ctf-impl.h
+++ b/libctf/ctf-impl.h
@@ -741,7 +741,6 @@ extern struct ctf_archive *ctf_arc_open_internal (const char *, int *);
 extern void ctf_arc_close_internal (struct ctf_archive *);
 extern const ctf_preamble_t *ctf_arc_bufpreamble (const ctf_sect_t *);
 extern void *ctf_set_open_errno (int *, int);
-extern unsigned long ctf_set_errno (ctf_dict_t *, int);
 extern void ctf_flip_header (ctf_header_t *);
 extern int ctf_flip (ctf_dict_t *, ctf_header_t *, unsigned char *, int);
 
diff --git a/libctf/ctf-inlines.h b/libctf/ctf-inlines.h
index 6bda68d68e6..86661348215 100644
--- a/libctf/ctf-inlines.h
+++ b/libctf/ctf-inlines.h
@@ -90,6 +90,12 @@ ctf_assert_internal (ctf_dict_t *fp, const char *file, size_t line,
   return expr;
 }
 
+static inline void
+ctf_set_errno (ctf_dict_t *fp, int err)
+{
+  fp->ctf_errno = err;
+}
+
 #ifdef	__cplusplus
 }
 #endif
diff --git a/libctf/ctf-labels.c b/libctf/ctf-labels.c
index 16b111b14df..9ac8aae6c26 100644
--- a/libctf/ctf-labels.c
+++ b/libctf/ctf-labels.c
@@ -48,12 +48,12 @@ ctf_label_topmost (ctf_dict_t *fp)
 
   if (num_labels == 0)
     {
-      (void) ctf_set_errno (fp, ECTF_NOLABELDATA);
+      ctf_set_errno (fp, ECTF_NOLABELDATA);
       return NULL;
     }
 
   if ((s = ctf_strraw (fp, (ctlp + num_labels - 1)->ctl_label)) == NULL)
-    (void) ctf_set_errno (fp, ECTF_CORRUPT);
+    ctf_set_errno (fp, ECTF_CORRUPT);
 
   return s;
 }
@@ -74,7 +74,10 @@ ctf_label_iter (ctf_dict_t *fp, ctf_label_f *func, void *arg)
     return -1;			/* errno is set for us.  */
 
   if (num_labels == 0)
-    return (ctf_set_errno (fp, ECTF_NOLABELDATA));
+    {
+      ctf_set_errno (fp, ECTF_NOLABELDATA);
+      return -1;
+    }
 
   for (i = 0; i < num_labels; i++, ctlp++)
     {
@@ -84,7 +87,8 @@ ctf_label_iter (ctf_dict_t *fp, ctf_label_f *func, void *arg)
 	  ctf_err_warn (fp, 0, ECTF_CORRUPT,
 			"failed to decode label %u with type %u",
 			ctlp->ctl_label, ctlp->ctl_type);
-	  return (ctf_set_errno (fp, ECTF_CORRUPT));
+	  ctf_set_errno (fp, ECTF_CORRUPT);
+	  return -1;
 	}
 
       linfo.ctb_type = ctlp->ctl_type;
@@ -133,8 +137,9 @@ ctf_label_info (ctf_dict_t *fp, const char *lname, ctf_lblinfo_t *linfo)
   if ((rc = ctf_label_iter (fp, label_info_cb, &cb_arg)) < 0)
     return rc;
 
-  if (rc != 1)
-    return (ctf_set_errno (fp, ECTF_NOLABEL));
+  if (rc == 1)
+    return 0;
 
-  return 0;
+  ctf_set_errno (fp, ECTF_NOLABEL);
+  return -1;
 }
diff --git a/libctf/ctf-link.c b/libctf/ctf-link.c
index 9babec2aa37..63da718ae4b 100644
--- a/libctf/ctf-link.c
+++ b/libctf/ctf-link.c
@@ -142,7 +142,8 @@ ctf_link_add_ctf_internal (ctf_dict_t *fp, ctf_archive_t *ctf,
  oom1:
   free (filename);
  oom:
-  return ctf_set_errno (fp, ENOMEM);
+  ctf_set_errno (fp, ENOMEM);
+  return -1;
 }
 
 /* Add a file, memory buffer, or unopened file (by name) to a link.
@@ -173,12 +174,18 @@ ctf_link_add (ctf_dict_t *fp, ctf_archive_t *ctf, const char *name,
 	      void *buf _libctf_unused_, size_t n _libctf_unused_)
 {
   if (buf)
-    return (ctf_set_errno (fp, ECTF_NOTYET));
+    {
+      ctf_set_errno (fp, ECTF_NOTYET);
+      return -1;
+    }
 
   if (!((ctf && name && !buf)
 	|| (name && !buf && !ctf)
 	|| (buf && name && !ctf)))
-    return (ctf_set_errno (fp, EINVAL));
+    {
+      ctf_set_errno (fp, EINVAL);
+      return -1;
+    }
 
   /* We can only lazily open files if libctf.so is in use rather than
      libctf-nobfd.so.  This is a little tricky: in shared libraries, we can use
@@ -187,21 +194,33 @@ ctf_link_add (ctf_dict_t *fp, ctf_archive_t *ctf, const char *name,
 
 #if defined (PIC)
   if (!buf && !ctf && name && !ctf_open)
-    return (ctf_set_errno (fp, ECTF_NEEDSBFD));
+    {
+      ctf_set_errno (fp, ECTF_NEEDSBFD);
+      return -1;
+    }
 #elif NOBFD
   if (!buf && !ctf && name)
-    return (ctf_set_errno (fp, ECTF_NEEDSBFD));
+    {
+      ctf_set_errno (fp, ECTF_NEEDSBFD);
+      return -1;
+    }
 #endif
 
   if (fp->ctf_link_outputs)
-    return (ctf_set_errno (fp, ECTF_LINKADDEDLATE));
+    {
+      ctf_set_errno (fp, ECTF_LINKADDEDLATE);
+      return -1;
+    }
   if (fp->ctf_link_inputs == NULL)
     fp->ctf_link_inputs = ctf_dynhash_create (ctf_hash_string,
 					      ctf_hash_eq_string, free,
 					      ctf_link_input_close);
 
   if (fp->ctf_link_inputs == NULL)
-    return (ctf_set_errno (fp, ENOMEM));
+    {
+      ctf_set_errno (fp, ENOMEM);
+      return -1;
+    }
 
   return ctf_link_add_ctf_internal (fp, ctf, NULL, name);
 }
@@ -378,7 +397,10 @@ ctf_link_add_cu_mapping (ctf_dict_t *fp, const char *from, const char *to)
 
   /* Mappings cannot be set up if per-CU output dicts already exist.  */
   if (fp->ctf_link_outputs && ctf_dynhash_elements (fp->ctf_link_outputs) != 0)
-      return (ctf_set_errno (fp, ECTF_LINKADDEDLATE));
+    {
+      ctf_set_errno (fp, ECTF_LINKADDEDLATE);
+      return -1;
+    }
 
   if (fp->ctf_link_in_cu_mapping == NULL)
     fp->ctf_link_in_cu_mapping = ctf_dynhash_create (ctf_hash_string,
@@ -582,7 +604,10 @@ ctf_link_one_variable (ctf_dict_t *fp, ctf_dict_t *in_fp, const char *name,
 
   if (check_variable (name, per_cu_out_fp, dst_type, &dvd))
     if (ctf_add_variable (per_cu_out_fp, name, dst_type) < 0)
-      return (ctf_set_errno (fp, ctf_errno (per_cu_out_fp)));
+      {
+	ctf_set_errno (fp, ctf_errno (per_cu_out_fp));
+	return -1;
+      }
   return 0;
 }
 
@@ -915,7 +940,10 @@ ctf_link_deduplicating_variables (ctf_dict_t *fp, ctf_dict_t **inputs,
 	    }
 	}
       if (ctf_errno (inputs[i]) != ECTF_NEXT_END)
-	return ctf_set_errno (fp, ctf_errno (inputs[i]));
+	{
+	  ctf_set_errno (fp, ctf_errno (inputs[i]));
+	  return -1;
+	}
 
       /* Next the symbols.  We integrate data symbols even though the compiler
 	 is currently doing the same, to allow the compiler to stop in
@@ -930,7 +958,10 @@ ctf_link_deduplicating_variables (ctf_dict_t *fp, ctf_dict_t **inputs,
 	    }
 	}
       if (ctf_errno (inputs[i]) != ECTF_NEXT_END)
-	return ctf_set_errno (fp, ctf_errno (inputs[i]));
+	{
+	  ctf_set_errno (fp, ctf_errno (inputs[i]));
+	  return -1;
+	}
 
       /* Finally the function symbols.  */
 
@@ -943,7 +974,10 @@ ctf_link_deduplicating_variables (ctf_dict_t *fp, ctf_dict_t **inputs,
 	    }
 	}
       if (ctf_errno (inputs[i]) != ECTF_NEXT_END)
-	return ctf_set_errno (fp, ctf_errno (inputs[i]));
+	{
+	  ctf_set_errno (fp, ctf_errno (inputs[i]));
+	  return -1;
+	}
     }
   return 0;
 }
@@ -1070,7 +1104,8 @@ ctf_link_deduplicating_one_symtypetab (ctf_dict_t *fp, ctf_dict_t *input,
 			_("symbol %s in input file %s found conflicting "
 			  "even when trying in per-CU dict."), name,
 			ctf_unnamed_cuname (input));
-	  return (ctf_set_errno (fp, ECTF_DUPLICATE));
+	  ctf_set_errno (fp, ECTF_DUPLICATE);
+    return -1;
 	}
     }
   if (ctf_errno (input) != ECTF_NEXT_END)
@@ -1330,7 +1365,8 @@ ctf_link_deduplicating_per_cu (ctf_dict_t *fp)
     {
       ctf_err_warn (fp, 0, err, _("iteration error in CU-mapped deduplicating "
 				  "link"));
-      return ctf_set_errno (fp, err);
+      ctf_set_errno (fp, err);
+      return -1;
     }
 
   return 0;
@@ -1503,7 +1539,10 @@ ctf_link (ctf_dict_t *fp, int flags)
 					       ctf_dict_close);
 
   if (fp->ctf_link_outputs == NULL)
-    return ctf_set_errno (fp, ENOMEM);
+    {
+      ctf_set_errno (fp, ENOMEM);
+      return -1;
+    }
 
   fp->ctf_flags |= LCTF_LINKING;
   ctf_link_deduplicating (fp);
diff --git a/libctf/ctf-lookup.c b/libctf/ctf-lookup.c
index c65849118cb..6dbc7cd70a6 100644
--- a/libctf/ctf-lookup.c
+++ b/libctf/ctf-lookup.c
@@ -30,7 +30,10 @@ grow_pptrtab (ctf_dict_t *fp, size_t new_len)
 
   if ((new_pptrtab = realloc (fp->ctf_pptrtab, sizeof (uint32_t)
 			      * new_len)) == NULL)
-    return (ctf_set_errno (fp, ENOMEM));
+    {
+      ctf_set_errno (fp, ENOMEM);
+      return -1;
+    }
 
   fp->ctf_pptrtab = new_pptrtab;
 
@@ -143,7 +146,10 @@ ctf_lookup_by_name_internal (ctf_dict_t *fp, ctf_dict_t *child,
   ctf_id_t ntype, ptype;
 
   if (name == NULL)
-    return (ctf_set_errno (fp, EINVAL));
+    {
+      ctf_set_errno (fp, EINVAL);
+      return CTF_ERR;
+    }
 
   for (p = name, end = name + strlen (name); *p != '\0'; p = q)
     {
@@ -292,7 +298,10 @@ ctf_lookup_by_name_internal (ctf_dict_t *fp, ctf_dict_t *child,
     }
 
   if (*p != '\0' || type == 0)
-    return (ctf_set_errno (fp, ECTF_SYNTAX));
+    {
+      ctf_set_errno (fp, ECTF_SYNTAX);
+      return CTF_ERR;
+    }
 
   return type;
 
@@ -306,13 +315,14 @@ ctf_lookup_by_name_internal (ctf_dict_t *fp, ctf_dict_t *child,
       if (fp->ctf_pptrtab_typemax < fp->ctf_typemax)
 	{
 	  if (refresh_pptrtab (fp, fp->ctf_parent) < 0)
-	    return -1;			/* errno is set for us.  */
+	    return CTF_ERR;			/* errno is set for us.  */
 	}
 
       if ((ptype = ctf_lookup_by_name_internal (fp->ctf_parent, fp,
 						name)) != CTF_ERR)
 	return ptype;
-      return (ctf_set_errno (fp, ctf_errno (fp->ctf_parent)));
+      ctf_set_errno (fp, ctf_errno (fp->ctf_parent));
+      return CTF_ERR;
     }
 
   return CTF_ERR;
@@ -336,7 +346,7 @@ ctf_lookup_by_id (ctf_dict_t **fpp, ctf_id_t type)
 
   if ((fp = ctf_get_dict (fp, type)) == NULL)
     {
-      (void) ctf_set_errno (*fpp, ECTF_NOPARENT);
+      ctf_set_errno (*fpp, ECTF_NOPARENT);
       return NULL;
     }
 
@@ -351,7 +361,7 @@ ctf_lookup_by_id (ctf_dict_t **fpp, ctf_id_t type)
 	  *fpp = fp;
 	  return &dtd->dtd_data;
 	}
-      (void) ctf_set_errno (*fpp, ECTF_BADID);
+      ctf_set_errno (*fpp, ECTF_BADID);
       return NULL;
     }
 
@@ -364,7 +374,7 @@ ctf_lookup_by_id (ctf_dict_t **fpp, ctf_id_t type)
       return (LCTF_INDEX_TO_TYPEPTR (fp, idx));
     }
 
-  (void) ctf_set_errno (*fpp, ECTF_BADID);
+  ctf_set_errno (*fpp, ECTF_BADID);
   return NULL;
 }
 
@@ -407,10 +417,12 @@ ctf_lookup_variable (ctf_dict_t *fp, const char *name)
 
           if ((ptype = ctf_lookup_variable (fp->ctf_parent, name)) != CTF_ERR)
             return ptype;
-          return (ctf_set_errno (fp, ctf_errno (fp->ctf_parent)));
+          ctf_set_errno (fp, ctf_errno (fp->ctf_parent));
+          return CTF_ERR;
         }
 
-      return (ctf_set_errno (fp, ECTF_NOTYPEDAT));
+      ctf_set_errno (fp, ECTF_NOTYPEDAT);
+      return CTF_ERR;
     }
 
   return ent->ctv_type;
@@ -622,13 +634,13 @@ ctf_lookup_symbol_idx (ctf_dict_t *fp, const char *symname)
 	  break;
 	default:
 	  ctf_set_errno (fp, ECTF_SYMTAB);
-	  return (unsigned long) -1;
+	  return CTF_ERR;
 	}
     }
 
   /* Searched everything, still not found.  */
 
-  return (unsigned long) -1;
+  return CTF_ERR;
 
  try_parent:
   if (fp->ctf_parent)
@@ -636,22 +648,22 @@ ctf_lookup_symbol_idx (ctf_dict_t *fp, const char *symname)
       unsigned long psym;
 
       if ((psym = ctf_lookup_symbol_idx (fp->ctf_parent, symname))
-          != (unsigned long) -1)
+          != CTF_ERR)
         return psym;
 
       ctf_set_errno (fp, ctf_errno (fp->ctf_parent));
-      return (unsigned long) -1;
+      return CTF_ERR;
     }
   else
     {
       ctf_set_errno (fp, err);
-      return (unsigned long) -1;
+      return CTF_ERR;
     }
 oom:
   ctf_set_errno (fp, ENOMEM);
   ctf_err_warn (fp, 0, ENOMEM, _("cannot allocate memory for symbol "
 				 "lookup hashtab"));
-  return (unsigned long) -1;
+  return CTF_ERR;
 
 }
 
@@ -673,7 +685,10 @@ ctf_symbol_next (ctf_dict_t *fp, ctf_next_t **it, const char **name,
   if (!i)
     {
       if ((i = ctf_next_create ()) == NULL)
-	return ctf_set_errno (fp, ENOMEM);
+	{
+	  ctf_set_errno (fp, ENOMEM);
+	  return CTF_ERR;
+	}
 
       i->cu.ctn_fp = fp;
       i->ctn_iter_fun = (void (*) (void)) ctf_symbol_next;
@@ -682,10 +697,16 @@ ctf_symbol_next (ctf_dict_t *fp, ctf_next_t **it, const char **name,
     }
 
   if ((void (*) (void)) ctf_symbol_next != i->ctn_iter_fun)
-    return (ctf_set_errno (fp, ECTF_NEXT_WRONGFUN));
+    {
+      ctf_set_errno (fp, ECTF_NEXT_WRONGFUN);
+      return CTF_ERR;
+    }
 
   if (fp != i->cu.ctn_fp)
-    return (ctf_set_errno (fp, ECTF_NEXT_WRONGFP));
+    {
+      ctf_set_errno (fp, ECTF_NEXT_WRONGFP);
+      return CTF_ERR;
+    }
 
   /* We intentionally use raw access, not ctf_lookup_by_symbol, to avoid
      incurring additional sorting cost for unsorted symtypetabs coming from the
@@ -701,7 +722,8 @@ ctf_symbol_next (ctf_dict_t *fp, ctf_next_t **it, const char **name,
       if (!dynh)
 	{
 	  ctf_next_destroy (i);
-	  return (ctf_set_errno (fp, ECTF_NEXT_END));
+	  ctf_set_errno (fp, ECTF_NEXT_END);
+	  return CTF_ERR;
 	}
 
       err = ctf_dynhash_next (dynh, &i->ctn_next, &dyn_name, &dyn_value);
@@ -710,7 +732,8 @@ ctf_symbol_next (ctf_dict_t *fp, ctf_next_t **it, const char **name,
 	{
 	  ctf_next_destroy (i);
 	  *it = NULL;
-	  return ctf_set_errno (fp, err);
+	  ctf_set_errno (fp, err);
+	  return CTF_ERR;
 	}
 
       *name = dyn_name;
@@ -786,7 +809,8 @@ ctf_symbol_next (ctf_dict_t *fp, ctf_next_t **it, const char **name,
  end:
   ctf_next_destroy (i);
   *it = NULL;
-  return (ctf_set_errno (fp, ECTF_NEXT_END));
+  ctf_set_errno (fp, ECTF_NEXT_END);
+  return CTF_ERR;
 }
 
 /* A bsearch function for function and object index names.  */
@@ -821,7 +845,7 @@ ctf_try_lookup_indexed (ctf_dict_t *fp, unsigned long symidx,
 	       "indexed symtypetab\n", symidx, symname);
 
   if (symname[0] == '\0')
-    return -1;					/* errno is set for us.  */
+    return CTF_ERR;					/* errno is set for us.  */
 
   if (is_function)
     {
@@ -835,7 +859,7 @@ ctf_try_lookup_indexed (ctf_dict_t *fp, unsigned long symidx,
 	      == NULL)
 	    {
 	      ctf_err_warn (fp, 0, 0, _("cannot sort function symidx"));
-	      return -1;				/* errno is set for us.  */
+	      return CTF_ERR;				/* errno is set for us.  */
 	    }
 	}
       symtypetab = (uint32_t *) (fp->ctf_buf + hp->cth_funcoff);
@@ -855,7 +879,7 @@ ctf_try_lookup_indexed (ctf_dict_t *fp, unsigned long symidx,
 	      == NULL)
 	    {
 	      ctf_err_warn (fp, 0, 0, _("cannot sort object symidx"));
-	      return -1;				/* errno is set for us. */
+	      return CTF_ERR;				/* errno is set for us. */
 	    }
 	}
 
@@ -878,7 +902,10 @@ ctf_try_lookup_indexed (ctf_dict_t *fp, unsigned long symidx,
 
   /* Should be impossible, but be paranoid.  */
   if ((idx - sxlate) > (ptrdiff_t) nidx)
-    return (ctf_set_errno (fp, ECTF_CORRUPT));
+    {
+      ctf_set_errno (fp, ECTF_CORRUPT);
+      return CTF_ERR;
+    }
 
   ctf_dprintf ("Symbol %lx (%s) is of type %x\n", symidx, symname,
 	       symtypetab[*idx]);
@@ -1014,7 +1041,10 @@ ctf_lookup_by_sym_or_name (ctf_dict_t *fp, unsigned long symidx,
       return ret;
     }
   else
-    return (ctf_set_errno (fp, err));
+    {
+      ctf_set_errno (fp, err);
+      return CTF_ERR;
+    }
 }
 
 /* Given a symbol table index, return the type of the function or data object
@@ -1046,7 +1076,10 @@ ctf_func_info (ctf_dict_t *fp, unsigned long symidx, ctf_funcinfo_t *fip)
     return -1;					/* errno is set for us.  */
 
   if (ctf_type_kind (fp, type) != CTF_K_FUNCTION)
-    return (ctf_set_errno (fp, ECTF_NOTFUNC));
+    {
+      ctf_set_errno (fp, ECTF_NOTFUNC);
+      return -1;
+    }
 
   return ctf_func_type_info (fp, type, fip);
 }
@@ -1064,7 +1097,10 @@ ctf_func_args (ctf_dict_t *fp, unsigned long symidx, uint32_t argc,
     return -1;					/* errno is set for us.  */
 
   if (ctf_type_kind (fp, type) != CTF_K_FUNCTION)
-    return (ctf_set_errno (fp, ECTF_NOTFUNC));
+    {
+      ctf_set_errno (fp, ECTF_NOTFUNC);
+      return -1;
+    }
 
   return ctf_func_type_args (fp, type, argc, argv);
 }
diff --git a/libctf/ctf-open.c b/libctf/ctf-open.c
index 35f635b6559..fa5f2aab732 100644
--- a/libctf/ctf-open.c
+++ b/libctf/ctf-open.c
@@ -1935,7 +1935,10 @@ ctf_parent_name_set (ctf_dict_t *fp, const char *name)
     free (fp->ctf_dynparname);
 
   if ((fp->ctf_dynparname = strdup (name)) == NULL)
-    return (ctf_set_errno (fp, ENOMEM));
+    {
+      ctf_set_errno (fp, ENOMEM);
+      return -1;
+    }
   fp->ctf_parname = fp->ctf_dynparname;
   return 0;
 }
@@ -1956,7 +1959,10 @@ ctf_cuname_set (ctf_dict_t *fp, const char *name)
     free (fp->ctf_dyncuname);
 
   if ((fp->ctf_dyncuname = strdup (name)) == NULL)
-    return (ctf_set_errno (fp, ENOMEM));
+    {
+      ctf_set_errno (fp, ENOMEM);
+      return -1;
+    }
   fp->ctf_cuname = fp->ctf_dyncuname;
   return 0;
 }
@@ -1969,10 +1975,16 @@ int
 ctf_import (ctf_dict_t *fp, ctf_dict_t *pfp)
 {
   if (fp == NULL || fp == pfp || (pfp != NULL && pfp->ctf_refcnt == 0))
-    return (ctf_set_errno (fp, EINVAL));
+    {
+      ctf_set_errno (fp, EINVAL);
+      return -1;
+    }
 
   if (pfp != NULL && pfp->ctf_dmodel != fp->ctf_dmodel)
-    return (ctf_set_errno (fp, ECTF_DMODEL));
+    {
+      ctf_set_errno (fp, ECTF_DMODEL);
+      return -1;
+    }
 
   if (fp->ctf_parent && !fp->ctf_parent_unreffed)
     ctf_dict_close (fp->ctf_parent);
@@ -2008,10 +2020,16 @@ int
 ctf_import_unref (ctf_dict_t *fp, ctf_dict_t *pfp)
 {
   if (fp == NULL || fp == pfp || (pfp != NULL && pfp->ctf_refcnt == 0))
-    return (ctf_set_errno (fp, EINVAL));
+    {
+      ctf_set_errno (fp, EINVAL);
+      return -1;
+    }
 
   if (pfp != NULL && pfp->ctf_dmodel != fp->ctf_dmodel)
-    return (ctf_set_errno (fp, ECTF_DMODEL));
+    {
+      ctf_set_errno (fp, ECTF_DMODEL);
+      return -1;
+    }
 
   if (fp->ctf_parent && !fp->ctf_parent_unreffed)
     ctf_dict_close (fp->ctf_parent);
@@ -2052,7 +2070,8 @@ ctf_setmodel (ctf_dict_t *fp, int model)
 	}
     }
 
-  return (ctf_set_errno (fp, EINVAL));
+  ctf_set_errno (fp, EINVAL);
+  return -1;
 }
 
 /* Return the data model constant for the CTF dict.  */
diff --git a/libctf/ctf-serialize.c b/libctf/ctf-serialize.c
index ba830a2b095..2d3756d31fd 100644
--- a/libctf/ctf-serialize.c
+++ b/libctf/ctf-serialize.c
@@ -123,7 +123,10 @@ symtypetab_density (ctf_dict_t *fp, ctf_dict_t *symfp, ctf_dynhash_t *symhash,
 
       if ((linker_known = ctf_dynhash_create (ctf_hash_string, ctf_hash_eq_string,
 					      NULL, NULL)) == NULL)
-	return (ctf_set_errno (fp, ENOMEM));
+	{
+	  ctf_set_errno (fp, ENOMEM);
+	  return -1;
+	}
 
       while ((err = ctf_dynhash_cnext (symfp->ctf_dynsyms, &i,
 				       &name, &ctf_sym)) == 0)
@@ -147,7 +150,8 @@ symtypetab_density (ctf_dict_t *fp, ctf_dict_t *symfp, ctf_dynhash_t *symhash,
 	  if (ctf_dynhash_cinsert (linker_known, name, ctf_sym) < 0)
 	    {
 	      ctf_dynhash_destroy (linker_known);
-	      return (ctf_set_errno (fp, ENOMEM));
+	      ctf_set_errno (fp, ENOMEM);
+	      return -1;
 	    }
 	}
       if (err != ECTF_NEXT_END)
@@ -155,7 +159,8 @@ symtypetab_density (ctf_dict_t *fp, ctf_dict_t *symfp, ctf_dynhash_t *symhash,
 	  ctf_err_warn (fp, 0, err, _("iterating over linker-known symbols during "
 				  "serialization"));
 	  ctf_dynhash_destroy (linker_known);
-	  return (ctf_set_errno (fp, err));
+	  ctf_set_errno (fp, err);
+	  return -1;
 	}
     }
 
@@ -219,7 +224,8 @@ symtypetab_density (ctf_dict_t *fp, ctf_dict_t *symfp, ctf_dynhash_t *symhash,
       ctf_err_warn (fp, 0, err, _("iterating over CTF symtypetab during "
 				  "serialization"));
       ctf_dynhash_destroy (linker_known);
-      return (ctf_set_errno (fp, err));
+      ctf_set_errno (fp, err);
+      return -1;
     }
 
   if (!(flags & CTF_SYMTYPETAB_FORCE_INDEXED))
@@ -236,7 +242,8 @@ symtypetab_density (ctf_dict_t *fp, ctf_dict_t *symfp, ctf_dynhash_t *symhash,
 	  ctf_err_warn (fp, 0, err, _("iterating over linker-known symbols "
 				      "during CTF serialization"));
 	  ctf_dynhash_destroy (linker_known);
-	  return (ctf_set_errno (fp, err));
+	  ctf_set_errno (fp, err);
+	  return -1;
 	}
     }
 
@@ -970,7 +977,10 @@ ctf_serialize (ctf_dict_t *fp)
   memset (&symstate, 0, sizeof (emit_symtypetab_state_t));
 
   if (!(fp->ctf_flags & LCTF_RDWR))
-    return (ctf_set_errno (fp, ECTF_RDONLY));
+    {
+      ctf_set_errno (fp, ECTF_RDONLY);
+      return -1;
+    }
 
   /* Update required?  */
   if (!(fp->ctf_flags & LCTF_DIRTY))
@@ -1026,7 +1036,10 @@ ctf_serialize (ctf_dict_t *fp)
   buf_size = sizeof (ctf_header_t) + hdr.cth_stroff + hdr.cth_strlen;
 
   if ((buf = malloc (buf_size)) == NULL)
-    return (ctf_set_errno (fp, EAGAIN));
+    {
+      ctf_set_errno (fp, EAGAIN);
+      return -1;
+    }
 
   memcpy (buf, &hdr, sizeof (ctf_header_t));
   t = (unsigned char *) buf + sizeof (ctf_header_t) + hdr.cth_objtoff;
@@ -1106,7 +1119,8 @@ ctf_serialize (ctf_dict_t *fp)
 				       1, &err)) == NULL)
     {
       free (buf);
-      return (ctf_set_errno (fp, err));
+      ctf_set_errno (fp, err);
+      return -1;
     }
 
   (void) ctf_setmodel (nfp, ctf_getmodel (fp));
@@ -1221,7 +1235,8 @@ ctf_serialize (ctf_dict_t *fp)
 
 oom:
   free (buf);
-  return (ctf_set_errno (fp, EAGAIN));
+  ctf_set_errno (fp, EAGAIN);
+  return -1;
 err:
   free (buf);
   return -1;					/* errno is set for us.  */
@@ -1248,7 +1263,10 @@ ctf_gzwrite (ctf_dict_t *fp, gzFile fd)
   while (resid != 0)
     {
       if ((len = gzwrite (fd, buf, resid)) <= 0)
-	return (ctf_set_errno (fp, errno));
+	{
+	  ctf_set_errno (fp, errno);
+	  return -1;
+	}
       resid -= len;
       buf += len;
     }
@@ -1258,7 +1276,10 @@ ctf_gzwrite (ctf_dict_t *fp, gzFile fd)
   while (resid != 0)
     {
       if ((len = gzwrite (fd, buf, resid)) <= 0)
-	return (ctf_set_errno (fp, errno));
+	{
+	  ctf_set_errno (fp, errno);
+	  return -1;
+	}
       resid -= len;
       buf += len;
     }
@@ -1378,7 +1399,8 @@ ctf_compress_write (ctf_dict_t *fp, int fd)
     {
       if ((len = write (fd, bp, buf_len)) < 0)
 	{
-	  err = ctf_set_errno (fp, errno);
+	  ctf_set_errno (fp, errno);
+	  err = CTF_ERR;
 	  ctf_err_warn (fp, 0, 0, _("ctf_compress_write: error writing"));
 	  goto ret;
 	}
@@ -1412,7 +1434,8 @@ ctf_write (ctf_dict_t *fp, int fd)
     {
       if ((len = write (fd, bp, buf_len)) < 0)
 	{
-	  err = ctf_set_errno (fp, errno);
+	  ctf_set_errno (fp, errno);
+	  err = CTF_ERR;
 	  ctf_err_warn (fp, 0, 0, _("ctf_compress_write: error writing"));
 	  goto ret;
 	}
diff --git a/libctf/ctf-string.c b/libctf/ctf-string.c
index 911e94700f1..ec8532fc47c 100644
--- a/libctf/ctf-string.c
+++ b/libctf/ctf-string.c
@@ -298,7 +298,10 @@ ctf_str_move_pending (ctf_dict_t *fp, uint32_t *new_ref, ptrdiff_t bytes)
     return 0;
 
   if (ctf_dynset_insert (fp->ctf_str_pending_ref, (void *) new_ref) < 0)
-    return (ctf_set_errno (fp, ENOMEM));
+    {
+      ctf_set_errno (fp, ENOMEM);
+      return -1;
+    }
 
   ctf_dynset_remove (fp->ctf_str_pending_ref,
 		     (void *) ((signed char *) new_ref - bytes));
diff --git a/libctf/ctf-types.c b/libctf/ctf-types.c
index c20ff825d9a..224a79c872b 100644
--- a/libctf/ctf-types.c
+++ b/libctf/ctf-types.c
@@ -119,7 +119,10 @@ ctf_member_next (ctf_dict_t *fp, ctf_id_t type, ctf_next_t **it,
 	return -1;			/* errno is set for us.  */
 
       if ((i = ctf_next_create ()) == NULL)
-	return ctf_set_errno (ofp, ENOMEM);
+	{
+	  ctf_set_errno (ofp, ENOMEM);
+	  return -1;
+	}
       i->cu.ctn_fp = ofp;
       i->ctn_tp = tp;
 
@@ -129,7 +132,8 @@ ctf_member_next (ctf_dict_t *fp, ctf_id_t type, ctf_next_t **it,
       if (kind != CTF_K_STRUCT && kind != CTF_K_UNION)
 	{
 	  ctf_next_destroy (i);
-	  return (ctf_set_errno (ofp, ECTF_NOTSOU));
+	  ctf_set_errno (ofp, ECTF_NOTSOU);
+	  return -1;
 	}
 
       if ((dtd = ctf_dynamic_type (fp, type)) != NULL)
@@ -150,14 +154,23 @@ ctf_member_next (ctf_dict_t *fp, ctf_id_t type, ctf_next_t **it,
     }
 
   if ((void (*) (void)) ctf_member_next != i->ctn_iter_fun)
-    return (ctf_set_errno (ofp, ECTF_NEXT_WRONGFUN));
+    {
+      ctf_set_errno (ofp, ECTF_NEXT_WRONGFUN);
+      return -1;
+    }
 
   if (ofp != i->cu.ctn_fp)
-    return (ctf_set_errno (ofp, ECTF_NEXT_WRONGFP));
+    {
+      ctf_set_errno (ofp, ECTF_NEXT_WRONGFP);
+      return -1;
+    }
 
   /* Resolve to the native dict of this type.  */
   if ((fp = ctf_get_dict (ofp, type)) == NULL)
-    return (ctf_set_errno (ofp, ECTF_NOPARENT));
+    {
+      ctf_set_errno (ofp, ECTF_NOPARENT);
+      return -1;
+    }
 
   max_vlen = LCTF_INFO_VLEN (fp, i->ctn_tp->ctt_info);
 
@@ -177,7 +190,10 @@ ctf_member_next (ctf_dict_t *fp, ctf_id_t type, ctf_next_t **it,
 
       if (ctf_struct_member (fp, &memb, i->ctn_tp, i->u.ctn_vlen, i->ctn_size,
 			     i->ctn_n) < 0)
-        return (ctf_set_errno (ofp, ctf_errno (fp)));
+	{
+	  ctf_set_errno (ofp, ctf_errno (fp));
+	  return -1;
+	}
 
       membname = ctf_strptr (fp, memb.ctlm_name);
 
@@ -221,7 +237,10 @@ ctf_member_next (ctf_dict_t *fp, ctf_id_t type, ctf_next_t **it,
 	}
 
       if (!ctf_assert (fp, (i->ctn_next == NULL)))
-        return (ctf_set_errno (ofp, ctf_errno (fp)));
+	{
+	  ctf_set_errno (ofp, ctf_errno (fp));
+	  return -1;
+	}
 
       i->ctn_type = 0;
       /* This sub-struct has ended: on to the next real member.  */
@@ -233,7 +252,8 @@ ctf_member_next (ctf_dict_t *fp, ctf_id_t type, ctf_next_t **it,
  end_iter:
   ctf_next_destroy (i);
   *it = NULL;
-  return ctf_set_errno (ofp, ECTF_NEXT_END);
+  ctf_set_errno (ofp, ECTF_NEXT_END);
+  return -1;
 }
 
 /* Iterate over the members of an ENUM.  We pass the string name and associated
@@ -426,7 +446,10 @@ ctf_type_next (ctf_dict_t *fp, ctf_next_t **it, int *flag, int want_hidden)
   if (!i)
     {
       if ((i = ctf_next_create ()) == NULL)
-	return ctf_set_errno (fp, ENOMEM);
+	{
+	  ctf_set_errno (fp, ENOMEM);
+	  return CTF_ERR;
+	}
 
       i->cu.ctn_fp = fp;
       i->ctn_type = 1;
@@ -435,10 +458,16 @@ ctf_type_next (ctf_dict_t *fp, ctf_next_t **it, int *flag, int want_hidden)
     }
 
   if ((void (*) (void)) ctf_type_next != i->ctn_iter_fun)
-    return (ctf_set_errno (fp, ECTF_NEXT_WRONGFUN));
+    {
+      ctf_set_errno (fp, ECTF_NEXT_WRONGFUN);
+      return CTF_ERR;
+    }
 
   if (fp != i->cu.ctn_fp)
-    return (ctf_set_errno (fp, ECTF_NEXT_WRONGFP));
+    {
+      ctf_set_errno (fp, ECTF_NEXT_WRONGFP);
+      return CTF_ERR;
+    }
 
   while (i->ctn_type <= fp->ctf_typemax)
     {
@@ -456,7 +485,8 @@ ctf_type_next (ctf_dict_t *fp, ctf_next_t **it, int *flag, int want_hidden)
     }
   ctf_next_destroy (i);
   *it = NULL;
-  return ctf_set_errno (fp, ECTF_NEXT_END);
+  ctf_set_errno (fp, ECTF_NEXT_END);
+  return CTF_ERR;
 }
 
 /* Iterate over every variable in the given CTF dict, in arbitrary order.
@@ -494,12 +524,18 @@ ctf_variable_next (ctf_dict_t *fp, ctf_next_t **it, const char **name)
   ctf_next_t *i = *it;
 
   if ((fp->ctf_flags & LCTF_CHILD) && (fp->ctf_parent == NULL))
-    return (ctf_set_errno (fp, ECTF_NOPARENT));
+    {
+      ctf_set_errno (fp, ECTF_NOPARENT);
+      return CTF_ERR;
+    }
 
   if (!i)
     {
       if ((i = ctf_next_create ()) == NULL)
-	return ctf_set_errno (fp, ENOMEM);
+	{
+	  ctf_set_errno (fp, ENOMEM);
+	  return CTF_ERR;
+	}
 
       i->cu.ctn_fp = fp;
       i->ctn_iter_fun = (void (*) (void)) ctf_variable_next;
@@ -509,10 +545,16 @@ ctf_variable_next (ctf_dict_t *fp, ctf_next_t **it, const char **name)
     }
 
   if ((void (*) (void)) ctf_variable_next != i->ctn_iter_fun)
-    return (ctf_set_errno (fp, ECTF_NEXT_WRONGFUN));
+    {
+      ctf_set_errno (fp, ECTF_NEXT_WRONGFUN);
+      return CTF_ERR;
+    }
 
   if (fp != i->cu.ctn_fp)
-    return (ctf_set_errno (fp, ECTF_NEXT_WRONGFP));
+    {
+      ctf_set_errno (fp, ECTF_NEXT_WRONGFP);
+      return CTF_ERR;
+    }
 
   if (!(fp->ctf_flags & LCTF_RDWR))
     {
@@ -538,7 +580,8 @@ ctf_variable_next (ctf_dict_t *fp, ctf_next_t **it, const char **name)
  end_iter:
   ctf_next_destroy (i);
   *it = NULL;
-  return ctf_set_errno (fp, ECTF_NEXT_END);
+  ctf_set_errno (fp, ECTF_NEXT_END);
+  return CTF_ERR;
 }
 
 /* Follow a given type through the graph for TYPEDEF, VOLATILE, CONST, and
@@ -560,7 +603,10 @@ ctf_type_resolve (ctf_dict_t *fp, ctf_id_t type)
   const ctf_type_t *tp;
 
   if (type == 0)
-    return (ctf_set_errno (ofp, ECTF_NONREPRESENTABLE));
+    {
+      ctf_set_errno (ofp, ECTF_NONREPRESENTABLE);
+      return CTF_ERR;
+    }
 
   while ((tp = ctf_lookup_by_id (&fp, type)) != NULL)
     {
@@ -575,18 +621,21 @@ ctf_type_resolve (ctf_dict_t *fp, ctf_id_t type)
 	    {
 	      ctf_err_warn (ofp, 0, ECTF_CORRUPT, _("type %lx cycle detected"),
 			    otype);
-	      return (ctf_set_errno (ofp, ECTF_CORRUPT));
+	      ctf_set_errno (ofp, ECTF_CORRUPT);
+	      return CTF_ERR;
 	    }
 	  prev = type;
 	  type = tp->ctt_type;
 	  break;
 	case CTF_K_UNKNOWN:
-	  return (ctf_set_errno (ofp, ECTF_NONREPRESENTABLE));
+	  ctf_set_errno (ofp, ECTF_NONREPRESENTABLE);
+	  return CTF_ERR;
 	default:
 	  return type;
 	}
       if (type == 0)
-	return (ctf_set_errno (ofp, ECTF_NONREPRESENTABLE));
+	ctf_set_errno (ofp, ECTF_NONREPRESENTABLE);
+	return CTF_ERR;
     }
 
   return CTF_ERR;		/* errno is set for us.  */
@@ -612,7 +661,10 @@ ctf_type_resolve_unsliced (ctf_dict_t *fp, ctf_id_t type)
       ctf_id_t ret;
 
       if ((ret = ctf_type_reference (fp, type)) == CTF_ERR)
-	return (ctf_set_errno (ofp, ctf_errno (fp)));
+	{
+	  ctf_set_errno (ofp, ctf_errno (fp));
+	  return CTF_ERR;
+	}
       return ret;
     }
   return type;
@@ -836,7 +888,7 @@ ctf_type_aname (ctf_dict_t *fp, ctf_id_t type)
     }
 
   if (cd.cd_enomem)
-    (void) ctf_set_errno (fp, ENOMEM);
+    ctf_set_errno (fp, ENOMEM);
 
   buf = ctf_decl_buf (&cd);
 
@@ -854,14 +906,14 @@ ctf_type_lname (ctf_dict_t *fp, ctf_id_t type, char *buf, size_t len)
   size_t slen;
 
   if (str == NULL)
-    return CTF_ERR;			/* errno is set for us.  */
+    return -1;			/* errno is set for us.  */
 
   slen = strlen (str);
   snprintf (buf, len, "%s", str);
   free (str);
 
   if (slen >= len)
-    (void) ctf_set_errno (fp, ECTF_NAMELEN);
+    ctf_set_errno (fp, ECTF_NAMELEN);
 
   return slen;
 }
@@ -956,7 +1008,8 @@ ctf_type_size (ctf_dict_t *fp, ctf_id_t type)
 
     case CTF_K_FORWARD:
       /* Forwards do not have a meaningful size.  */
-      return (ctf_set_errno (ofp, ECTF_INCOMPLETE));
+      ctf_set_errno (ofp, ECTF_INCOMPLETE);
+      return -1;
 
     default: /* including slices of enums, etc */
       return (ctf_get_ctt_size (fp, tp, NULL, NULL));
@@ -1039,7 +1092,8 @@ ctf_type_align (ctf_dict_t *fp, ctf_id_t type)
 
     case CTF_K_FORWARD:
       /* Forwards do not have a meaningful alignment.  */
-      return (ctf_set_errno (ofp, ECTF_INCOMPLETE));
+      ctf_set_errno (ofp, ECTF_INCOMPLETE);
+      return -1;
 
     default:  /* including slices of enums, etc */
       return (ctf_get_ctt_size (fp, tp, NULL, NULL));
@@ -1139,7 +1193,8 @@ ctf_type_reference (ctf_dict_t *fp, ctf_id_t type)
 	return sp->cts_type;
       }
     default:
-      return (ctf_set_errno (ofp, ECTF_NOTREF));
+      ctf_set_errno (ofp, ECTF_NOTREF);
+      return CTF_ERR;
     }
 }
 
@@ -1164,15 +1219,22 @@ ctf_type_pointer (ctf_dict_t *fp, ctf_id_t type)
     return (LCTF_INDEX_TO_TYPE (fp, ntype, (fp->ctf_flags & LCTF_CHILD)));
 
   if ((type = ctf_type_resolve (fp, type)) == CTF_ERR)
-    return (ctf_set_errno (ofp, ECTF_NOTYPE));
+    {
+      ctf_set_errno (ofp, ECTF_NOTYPE);
+      return CTF_ERR;
+    }
 
   if (ctf_lookup_by_id (&fp, type) == NULL)
-    return (ctf_set_errno (ofp, ECTF_NOTYPE));
+    {
+      ctf_set_errno (ofp, ECTF_NOTYPE);
+      return CTF_ERR;
+    }
 
   if ((ntype = fp->ctf_ptrtab[LCTF_TYPE_TO_INDEX (fp, type)]) != 0)
     return (LCTF_INDEX_TO_TYPE (fp, ntype, (fp->ctf_flags & LCTF_CHILD)));
 
-  return (ctf_set_errno (ofp, ECTF_NOTYPE));
+  ctf_set_errno (ofp, ECTF_NOTYPE);
+  return CTF_ERR;
 }
 
 /* Return the encoding for the specified INTEGER, FLOAT, or ENUM.  */
@@ -1235,7 +1297,8 @@ ctf_type_encoding (ctf_dict_t *fp, ctf_id_t type, ctf_encoding_t *ep)
 	break;
       }
     default:
-      return (ctf_set_errno (ofp, ECTF_NOTINTFP));
+      ctf_set_errno (ofp, ECTF_NOTINTFP);
+      return -1;
     }
 
   return 0;
@@ -1370,7 +1433,10 @@ ctf_member_count (ctf_dict_t *fp, ctf_id_t type)
   kind = LCTF_INFO_KIND (fp, tp->ctt_info);
 
   if (kind != CTF_K_STRUCT && kind != CTF_K_UNION && kind != CTF_K_ENUM)
-    return (ctf_set_errno (ofp, ECTF_NOTSUE));
+    {
+      ctf_set_errno (ofp, ECTF_NOTSUE);
+      return -1;
+    }
 
   return LCTF_INFO_VLEN (fp, tp->ctt_info);
 }
@@ -1398,7 +1464,10 @@ ctf_member_info (ctf_dict_t *fp, ctf_id_t type, const char *name,
   kind = LCTF_INFO_KIND (fp, tp->ctt_info);
 
   if (kind != CTF_K_STRUCT && kind != CTF_K_UNION)
-    return (ctf_set_errno (ofp, ECTF_NOTSOU));
+    {
+      ctf_set_errno (ofp, ECTF_NOTSOU);
+      return -1;
+    }
 
   n = LCTF_INFO_VLEN (fp, tp->ctt_info);
   if ((dtd = ctf_dynamic_type (fp, type)) != NULL)
@@ -1418,7 +1487,10 @@ ctf_member_info (ctf_dict_t *fp, ctf_id_t type, const char *name,
       const char *membname;
 
       if (ctf_struct_member (fp, &memb, tp, vlen, vbytes, i) < 0)
-        return (ctf_set_errno (ofp, ctf_errno (fp)));
+	{
+	  ctf_set_errno (ofp, ctf_errno (fp));
+	  return -1;
+	}
 
       membname = ctf_strptr (fp, memb.ctlm_name);
 
@@ -1439,7 +1511,8 @@ ctf_member_info (ctf_dict_t *fp, ctf_id_t type, const char *name,
 	}
     }
 
-  return (ctf_set_errno (ofp, ECTF_NOMEMBNAM));
+  ctf_set_errno (ofp, ECTF_NOMEMBNAM);
+  return -1;
 }
 
 /* Return the array type, index, and size information for the specified ARRAY.  */
@@ -1457,7 +1530,10 @@ ctf_array_info (ctf_dict_t *fp, ctf_id_t type, ctf_arinfo_t *arp)
     return -1;			/* errno is set for us.  */
 
   if (LCTF_INFO_KIND (fp, tp->ctt_info) != CTF_K_ARRAY)
-    return (ctf_set_errno (ofp, ECTF_NOTARRAY));
+    {
+      ctf_set_errno (ofp, ECTF_NOTARRAY);
+      return -1;
+    }
 
   if ((dtd = ctf_dynamic_type (ofp, type)) != NULL)
     ap = (const ctf_array_t *) dtd->dtd_vlen;
@@ -1584,7 +1660,10 @@ ctf_func_type_info (ctf_dict_t *fp, ctf_id_t type, ctf_funcinfo_t *fip)
   kind = LCTF_INFO_KIND (fp, tp->ctt_info);
 
   if (kind != CTF_K_FUNCTION)
-    return (ctf_set_errno (ofp, ECTF_NOTFUNC));
+    {
+      ctf_set_errno (ofp, ECTF_NOTFUNC);
+      return -1;
+    }
 
   fip->ctc_return = tp->ctt_type;
   fip->ctc_flags = 0;
@@ -1697,7 +1776,10 @@ ctf_type_rvisit (ctf_dict_t *fp, ctf_id_t type, ctf_visit_f *func,
       ctf_lmember_t memb;
 
       if (ctf_struct_member (fp, &memb, tp, vlen, vbytes, i) < 0)
-        return (ctf_set_errno (ofp, ctf_errno (fp)));
+	{
+	  ctf_set_errno (ofp, ctf_errno (fp));
+	  return -1;
+	}
 
       if ((rc = ctf_type_rvisit (fp, memb.ctlm_type,
 				 func, arg, ctf_strptr (fp, memb.ctlm_name),
diff --git a/libctf/ctf-util.c b/libctf/ctf-util.c
index 9f83ab9ab0b..e0d412df390 100644
--- a/libctf/ctf-util.c
+++ b/libctf/ctf-util.c
@@ -255,16 +255,6 @@ ctf_set_open_errno (int *errp, int error)
   return NULL;
 }
 
-/* Store the specified error code into the CTF dict, and then return CTF_ERR /
-   -1 for the benefit of the caller. */
-
-unsigned long
-ctf_set_errno (ctf_dict_t *fp, int err)
-{
-  fp->ctf_errno = err;
-  return CTF_ERR;
-}
-
 /* Create a ctf_next_t.  */
 
 ctf_next_t *
-- 
2.25.1


  reply	other threads:[~2023-10-05  8:44 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-24 11:32 [PATCH] libctf: ctf_member_next needs to return (ssize_t)-1 on error Torbjörn SVENSSON
2023-08-25  2:22 ` Alan Modra
2023-08-25 16:53   ` [PATCH v2] " Torbjörn SVENSSON
2023-08-30  8:34     ` Torbjorn SVENSSON
2023-08-30  9:39       ` Alan Modra
2023-09-07 12:10         ` Nick Alcock
2023-09-08 12:58           ` Torbjorn SVENSSON
2023-09-12 14:23             ` Nick Alcock
2023-09-12 18:44               ` Torbjorn SVENSSON
2023-09-13  9:57               ` [PATCH v3] " Torbjörn SVENSSON
2023-09-13 18:37                 ` Nick Alcock
2023-09-13 20:20                   ` Torbjorn SVENSSON
2023-09-20 17:44                     ` Torbjorn SVENSSON
2023-09-26 14:51                     ` Nick Alcock
2023-09-26 17:28                       ` [PATCH v4] " Torbjörn SVENSSON
2023-09-26 17:49                       ` [PATCH v3] " Torbjorn SVENSSON
2023-09-28 16:41                         ` Nick Alcock
2023-09-29 12:11                           ` Torbjorn SVENSSON
2023-10-02 10:57                             ` Nick Alcock
2023-10-03 12:59                               ` Torbjorn SVENSSON
2023-10-03 20:53                                 ` Nick Alcock
2023-10-05  8:39                                   ` Torbjörn SVENSSON [this message]
2023-10-09 10:27                                     ` [PATCH v5] libctf: Sanitize error types for PR 30836 Nick Alcock
2023-10-09 14:44                                       ` [PATCH v6] " Torbjörn SVENSSON
2023-10-09 15:11                                         ` [PATCH v7] " Torbjörn SVENSSON
2023-10-11 11:14                                           ` Nick Alcock
2023-10-13 14:01                                           ` [PATCH] libctf: check for problems with error returns Nick Alcock
2023-10-13 18:31                                             ` Torbjorn SVENSSON
2023-10-15 19:18                                               ` Nick Alcock
2023-10-16 12:51                                                 ` [PATCH v8] libctf: Sanitize error types for PR 30836 Torbjörn SVENSSON
2023-10-17 15:15                                                   ` Nick Alcock
2023-10-17 15:35                                                     ` Torbjorn SVENSSON
2023-10-17 18:54                                                       ` [PATCH] libctf: Return CTF_ERR in ctf_type_resolve_unsliced " Torbjörn SVENSSON
2023-10-17 19:40                                                         ` Nick Alcock
2023-10-18  7:40                                                           ` Torbjorn SVENSSON
2023-10-20 17:01                                                             ` Nick Alcock
2023-10-16 13:02                                                 ` [PATCH] libctf: check for problems with error returns Torbjorn SVENSSON
2023-10-17 14:45                                                   ` Nick Alcock
2024-01-30 12:46                                             ` Andreas Schwab
2024-01-30 14:22                                               ` Nick Alcock
2024-01-30 14:27                                                 ` Andreas Schwab
2024-03-09  2:44                                                   ` Sam James
2024-03-11 15:14                                                     ` Nick Alcock
2024-03-12  6:52                                                       ` Sam James

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231005083920.2676339-1-torbjorn.svensson@foss.st.com \
    --to=torbjorn.svensson@foss.st.com \
    --cc=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=nick.alcock@oracle.com \
    --cc=yvan.roux@foss.st.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).