+2020-07-22  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ctf-impl.h (ctf_dtdef_t) <dtu_argv>: Fix type.
+       * ctf-create.c (ctf_add_function): Check for unimplemented type
+       and populate at the same time.  Populate one-by-one, not via
+       memcpy.
+       (ctf_serialize): Remove unnecessary cast.
+       * ctf-types.c (ctf_func_type_info): Likewise.
+       (ctf_func_type_args): Likewise.  Fix comment typo.
+
 2020-07-22  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf-create.c (ctf_add_reftype): Support refs to type zero.
 
            uint32_t argc;
 
            for (argc = 0; argc < vlen; argc++)
-             *argv++ = (uint32_t) dtd->dtd_u.dtu_argv[argc];
+             *argv++ = dtd->dtd_u.dtu_argv[argc];
 
            if (vlen & 1)
              *argv++ = 0;      /* Pad to 4-byte boundary.  */
   ctf_dtdef_t *dtd;
   ctf_id_t type;
   uint32_t vlen;
-  ctf_id_t *vdat = NULL;
+  uint32_t *vdat = NULL;
   ctf_file_t *tmp = fp;
   size_t i;
 
       && ctf_lookup_by_id (&tmp, ctc->ctc_return) == NULL)
     return CTF_ERR;            /* errno is set for us.  */
 
-  for (i = 0; i < ctc->ctc_argc; i++)
-    {
-      tmp = fp;
-      if (argv[i] != 0 && ctf_lookup_by_id (&tmp, argv[i]) == NULL)
-       return CTF_ERR;         /* errno is set for us.  */
-    }
-
   if (vlen > CTF_MAX_VLEN)
     return (ctf_set_errno (fp, EOVERFLOW));
 
   if (vlen != 0 && (vdat = malloc (sizeof (ctf_id_t) * vlen)) == NULL)
     return (ctf_set_errno (fp, EAGAIN));
 
+  for (i = 0; i < ctc->ctc_argc; i++)
+    {
+      tmp = fp;
+      if (argv[i] != 0 && ctf_lookup_by_id (&tmp, argv[i]) == NULL)
+       {
+         free (vdat);
+         return CTF_ERR;          /* errno is set for us.  */
+       }
+      vdat[i] = (uint32_t) argv[i];
+    }
+
   if ((type = ctf_add_generic (fp, flag, NULL, CTF_K_FUNCTION,
                               &dtd)) == CTF_ERR)
     {
   dtd->dtd_data.ctt_info = CTF_TYPE_INFO (CTF_K_FUNCTION, flag, vlen);
   dtd->dtd_data.ctt_type = (uint32_t) ctc->ctc_return;
 
-  memcpy (vdat, argv, sizeof (ctf_id_t) * ctc->ctc_argc);
   if (ctc->ctc_flags & CTF_FUNC_VARARG)
     vdat[vlen - 1] = 0;                   /* Add trailing zero to indicate varargs.  */
   dtd->dtd_u.dtu_argv = vdat;
 
     ctf_list_t dtu_members;    /* struct, union, or enum */
     ctf_arinfo_t dtu_arr;      /* array */
     ctf_encoding_t dtu_enc;    /* integer or float */
-    ctf_id_t *dtu_argv;                /* function */
+    uint32_t *dtu_argv;                /* function */
     ctf_slice_t dtu_slice;     /* slice */
   } dtd_u;
 } ctf_dtdef_t;
 
   if ((dtd = ctf_dynamic_type (fp, type)) == NULL)
     args = (uint32_t *) ((uintptr_t) tp + increment);
   else
-    args = (uint32_t *) dtd->dtd_u.dtu_argv;
+    args = dtd->dtd_u.dtu_argv;
 
   if (fip->ctc_argc != 0 && args[fip->ctc_argc - 1] == 0)
     {
   return 0;
 }
 
-/* Given a type ID relating to a function type,, return the arguments for the
+/* Given a type ID relating to a function type, return the arguments for the
    function.  */
 
 int
   if ((dtd = ctf_dynamic_type (fp, type)) == NULL)
     args = (uint32_t *) ((uintptr_t) tp + increment);
   else
-    args = (uint32_t *) dtd->dtd_u.dtu_argv;
+    args = dtd->dtd_u.dtu_argv;
 
   for (argc = MIN (argc, f.ctc_argc); argc != 0; argc--)
     *argv++ = *args++;