Fix overflow detection in the Z80 assembler.
[binutils-gdb.git] / gas / config / tc-ns32k.c
index dfa8b426585e70e37c1986f7019153673c0b5f30..98fa520b9ba1f2b6ac3fd392b614484267b1154f 100644 (file)
@@ -1,5 +1,5 @@
 /* ns32k.c  -- Assemble on the National Semiconductor 32k series
-   Copyright (C) 1987-2020 Free Software Foundation, Inc.
+   Copyright (C) 1987-2021 Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
 
@@ -442,7 +442,7 @@ addr_mode (char *operand,
     case 'e':
       if (str[strl - 1] != ']')
        {
-         if ((!strncmp (str, "ext(", 4)) && strl > 7)
+         if ((startswith (str, "ext(")) && strl > 7)
            {                           /* external */
              addrmodeP->disp[0] = str + 4;
              i = 0;
@@ -496,7 +496,7 @@ addr_mode (char *operand,
       /* Fall through.  */
 
     case 3:
-      if (!strncmp (str, "tos", 3))
+      if (startswith (str, "tos"))
        {
          addrmodeP->mode = 23; /* TopOfStack */
          return -1;
@@ -513,11 +513,11 @@ addr_mode (char *operand,
        {
          if (str[strl - 2] == ')')
            {
-             if (!strncmp (&str[strl - 5], "(fp", 3))
+             if (startswith (&str[strl - 5], "(fp"))
                mode = 16;              /* Memory Relative.  */
-             else if (!strncmp (&str[strl - 5], "(sp", 3))
+             else if (startswith (&str[strl - 5], "(sp"))
                mode = 17;
-             else if (!strncmp (&str[strl - 5], "(sb", 3))
+             else if (startswith (&str[strl - 5], "(sb"))
                mode = 18;
 
              if (mode != DEFAULT)
@@ -568,13 +568,13 @@ addr_mode (char *operand,
              /* Fall through.  */
 
            default:
-             if (!strncmp (&str[strl - 4], "(fp", 3))
+             if (startswith (&str[strl - 4], "(fp"))
                mode = 24;
-             else if (!strncmp (&str[strl - 4], "(sp", 3))
+             else if (startswith (&str[strl - 4], "(sp"))
                mode = 25;
-             else if (!strncmp (&str[strl - 4], "(sb", 3))
+             else if (startswith (&str[strl - 4], "(sb"))
                mode = 26;
-             else if (!strncmp (&str[strl - 4], "(pc", 3))
+             else if (startswith (&str[strl - 4], "(pc"))
                mode = 27;
 
              if (mode != DEFAULT)
@@ -1103,7 +1103,8 @@ parse (const char *line, int recursive_level)
       c = *lineptr;
       *(char *) lineptr = '\0';
 
-      if (!(desc = (struct ns32k_opcode *) str_hash_find (inst_hash_handle, line)))
+      desc = (struct ns32k_opcode *) str_hash_find (inst_hash_handle, line);
+      if (!desc)
        as_fatal (_("No such opcode"));
 
       *(char *) lineptr = c;
@@ -1901,7 +1902,8 @@ md_begin (void)
 
   endop = ns32k_opcodes + sizeof (ns32k_opcodes) / sizeof (ns32k_opcodes[0]);
   for (ptr = ns32k_opcodes; ptr < endop; ptr++)
-    str_hash_insert (inst_hash_handle, ptr->name, (char *) ptr);
+    if (str_hash_insert (inst_hash_handle, ptr->name, ptr, 0) != NULL)
+      as_fatal (_("duplicate %s"), ptr->name);
 
   /* Some private space please!  */
   freeptr_static = XNEWVEC (char, PRIVATE_SIZE);
@@ -1915,7 +1917,7 @@ md_begin (void)
 const char *
 md_atof (int type, char *litP, int *sizeP)
 {
-  return ieee_md_atof (type, litP, sizeP, FALSE);
+  return ieee_md_atof (type, litP, sizeP, false);
 }
 \f
 int