#define BND_PREFIX     0x04
 #define NOTRACK_PREFIX 0x05
 
-static int
+static enum {
+  ckp_okay,
+  ckp_bogus,
+  ckp_fetch_error,
+}
 ckprefix (instr_info *ins)
 {
   int newrex, i, length;
   /* The maximum instruction length is 15bytes.  */
   while (length < MAX_CODE_LENGTH - 1)
     {
-      FETCH_DATA (ins->info, ins->codep + 1);
+      if (!fetch_code (ins->info, ins->codep + 1))
+       return ckp_fetch_error;
       newrex = 0;
       switch (*ins->codep)
        {
          if (ins->address_mode == mode_64bit)
            newrex = *ins->codep;
          else
-           return 1;
+           return ckp_okay;
          ins->last_rex_prefix = i;
          break;
        case 0xf3:
              ins->codep++;
              /* This ensures that the previous REX prefixes are noticed
                 as unused prefixes, as in the return case below.  */
-             ins->rex_used = ins->rex;
-             return 1;
+             return ins->rex ? ckp_bogus : ckp_okay;
            }
          ins->prefixes = PREFIX_FWAIT;
          break;
        default:
-         return 1;
+         return ckp_okay;
        }
       /* Rex is ignored when followed by another prefix.  */
       if (ins->rex)
-       {
-         ins->rex_used = ins->rex;
-         return 1;
-       }
+       return ckp_bogus;
       if (*ins->codep != FWAIT_OPCODE)
        ins->all_prefixes[i++] = *ins->codep;
       ins->rex = newrex;
       ins->codep++;
       length++;
     }
-  return 0;
+  return ckp_bogus;
 }
 
 /* Return the name of the prefix byte PREF, or NULL if PREF is not a
 
   sizeflag = priv.orig_sizeflag;
 
-  if (!ckprefix (&ins) || ins.rex_used)
+  switch (ckprefix (&ins))
     {
+    case ckp_okay:
+      break;
+
+    case ckp_bogus:
       /* Too many prefixes or unused REX prefixes.  */
       for (i = 0;
           i < (int) ARRAY_SIZE (ins.all_prefixes) && ins.all_prefixes[i];
                         (i == 0 ? "" : " "),
                         prefix_name (&ins, ins.all_prefixes[i], sizeflag));
       return i;
+
+    case ckp_fetch_error:
+      return fetch_error (&ins);
     }
 
   ins.insn_codep = ins.codep;