Automatic date update in version.in
[binutils-gdb.git] / bfd / wasm-module.c
index 6382e92d5f5bb53b424f96bf609e8881a5c1de75..f6afa054db0061734d07a1e93de31fcc387147d9 100644 (file)
@@ -1,5 +1,5 @@
 /* BFD back-end for WebAssembly modules.
-   Copyright (C) 2017-2021 Free Software Foundation, Inc.
+   Copyright (C) 2017-2022 Free Software Foundation, Inc.
 
    Based on srec.c, mmo.c, and binary.c
 
    https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md. */
 
 #include "sysdep.h"
-#include "alloca-conf.h"
 #include "bfd.h"
 #include "libiberty.h"
 #include "libbfd.h"
 #include "wasm-module.h"
 
-#ifdef HAVE_LIMITS_H
 #include <limits.h>
-#endif
 #ifndef CHAR_BIT
 #define CHAR_BIT 8
 #endif
@@ -185,12 +182,9 @@ wasm_write_uleb128 (bfd *abfd, bfd_vma v)
 #define READ_LEB128(x, p, end)                                         \
   do                                                                   \
     {                                                                  \
-      unsigned int length_read;                                                \
-      (x) = _bfd_safe_read_leb128 (abfd, (p), &length_read,            \
-                                  false, (end));                       \
-      (p) += length_read;                                              \
-      if (length_read == 0)                                            \
+      if ((p) >= (end))                                                        \
        goto error_return;                                              \
+      (x) = _bfd_safe_read_leb128 (abfd, &(p), false, (end));          \
     }                                                                  \
   while (0)
 
@@ -363,7 +357,8 @@ wasm_scan_name_function_section (bfd *abfd, sec_ptr asect)
   return true;
 
  error_return:
-  bfd_release (abfd, symbols);
+  if (symbols)
+    bfd_release (abfd, symbols);
   return false;
 }