gdbarch-selftests.c: No longer error out if debugging something
[deliverable/binutils-gdb.git] / bfd / wasm-module.c
index 14e7386be1ba77b77f2392306952ec442ddbe642..06a964c12df1738206febba3af7dd67ee82bb722 100644 (file)
@@ -1,5 +1,5 @@
 /* BFD back-end for WebAssembly modules.
-   Copyright (C) 2017-2018 Free Software Foundation, Inc.
+   Copyright (C) 2017-2020 Free Software Foundation, Inc.
 
    Based on srec.c, mmo.c, and binary.c
 
@@ -28,9 +28,7 @@
 #include "sysdep.h"
 #include "alloca-conf.h"
 #include "bfd.h"
-#include "sysdep.h"
 #include <limits.h>
-#include "bfd_stdint.h"
 #include "libiberty.h"
 #include "libbfd.h"
 #include "wasm-module.h"
@@ -113,18 +111,28 @@ wasm_read_leb128 (bfd *             abfd,
   unsigned int num_read = 0;
   unsigned int shift = 0;
   unsigned char byte = 0;
-  bfd_boolean success = FALSE;
+  int status = 1;
 
   while (bfd_bread (&byte, 1, abfd) == 1)
     {
       num_read++;
 
-      result |= ((bfd_vma) (byte & 0x7f)) << shift;
+      if (shift < sizeof (result) * 8)
+       {
+         result |= ((bfd_vma) (byte & 0x7f)) << shift;
+         if ((result >> shift) != (byte & 0x7f))
+           /* Overflow.  */
+           status |= 2;
+         shift += 7;
+       }
+      else if ((byte & 0x7f) != 0)
+       status |= 2;
 
-      shift += 7;
       if ((byte & 0x80) == 0)
        {
-         success = TRUE;
+         status &= ~1;
+         if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
+           result |= -((bfd_vma) 1 << shift);
          break;
        }
     }
@@ -132,10 +140,7 @@ wasm_read_leb128 (bfd *              abfd,
   if (length_return != NULL)
     *length_return = num_read;
   if (error_return != NULL)
-    *error_return = ! success;
-
-  if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
-    result |= -((bfd_vma) 1 << shift);
+    *error_return = status != 0;
 
   return result;
 }
@@ -773,7 +778,7 @@ wasm_object_p (bfd *abfd)
 /* BFD_JUMP_TABLE_SYMBOLS */
 #define wasm_get_symbol_version_string   _bfd_nosymbols_get_symbol_version_string
 #define wasm_bfd_is_local_label_name      bfd_generic_is_local_label_name
-#define wasm_bfd_is_target_special_symbol ((bfd_boolean (*) (bfd *, asymbol *)) (bfd_boolean (*)) bfd_false)
+#define wasm_bfd_is_target_special_symbol _bfd_bool_bfd_asymbol_false
 #define wasm_get_lineno                          _bfd_nosymbols_get_lineno
 #define wasm_find_nearest_line           _bfd_nosymbols_find_nearest_line
 #define wasm_find_line                   _bfd_nosymbols_find_line
@@ -811,16 +816,16 @@ const bfd_target wasm_vec =
     _bfd_dummy_target,
   },
   {
-    bfd_false,
+    _bfd_bool_bfd_false_error,
     wasm_mkobject,
     _bfd_generic_mkarchive,
-    bfd_false,
+    _bfd_bool_bfd_false_error,
   },
   {                            /* bfd_write_contents.  */
-    bfd_false,
+    _bfd_bool_bfd_false_error,
     wasm_write_object_contents,
     _bfd_write_archive_contents,
-    bfd_false,
+    _bfd_bool_bfd_false_error,
   },
 
   BFD_JUMP_TABLE_GENERIC (_bfd_generic),
This page took 0.025481 seconds and 4 git commands to generate.