]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Add checked_read_leb128
authorPetr Machata <pmachata@redhat.com>
Wed, 6 Oct 2010 18:31:14 +0000 (20:31 +0200)
committerPetr Machata <pmachata@redhat.com>
Wed, 6 Oct 2010 18:31:14 +0000 (20:31 +0200)
- this is similar to read_ctx_read_var
- also drop a bunch of C-isms

dwarflint/checked_read.cc
dwarflint/checked_read.hh

index ced62beac24f74b9ae89a747e319f4e0e7aa2eee..0c74b42a919d73c31af3d17fdc1a5d12396e5d88 100644 (file)
@@ -31,6 +31,8 @@
 #endif
 
 #include <dwarf.h>
+#include <cassert>
+
 #include "checked_read.hh"
 #include "messages.hh"
 
@@ -113,8 +115,8 @@ checked_read_uleb128 (struct read_ctx *ctx, uint64_t *ret,
 }
 
 bool
-checked_read_sleb128 (struct read_ctx *ctx, int64_t *ret,
-                     struct where *where, const char *what)
+checked_read_sleb128 (read_ctx *ctx, int64_t *ret,
+                     where *where, const char *what)
 {
   const unsigned char *ptr = ctx->ptr;
   int st = read_ctx_read_sleb128 (ctx, ret);
@@ -129,3 +131,20 @@ checked_read_sleb128 (struct read_ctx *ctx, int64_t *ret,
     }
   return st >= 0;
 }
+
+bool
+checked_read_leb128 (read_ctx *ctx, form_width_t width, uint64_t *ret,
+                    where *where, const char *what)
+{
+  assert (width == fw_sleb || width == fw_uleb);
+  if (width == fw_sleb)
+    {
+      int64_t svalue;
+      if (!checked_read_sleb128 (ctx, &svalue, where, what))
+       return false;
+      *ret = (uint64_t) svalue;
+      return true;
+    }
+  else
+    return checked_read_uleb128 (ctx, ret, where, what);
+}
index caeba92d7b4274c910206556a2c7db41f9e44b01..316db3696f07bd391a3cfd67bc00ac2f53e898af 100644 (file)
 #define DWARFLINT_CHECKED_READ_HH
 
 #include "readctx.h"
+#include "where.h"
+#include "tables.hh"
 
-#ifdef __cplusplus
-extern "C"
-{
-#endif
+bool read_size_extra (read_ctx *ctx, uint32_t size32, uint64_t *sizep,
+                     int *offset_sizep, where *where);
 
-bool read_size_extra (struct read_ctx *ctx, uint32_t size32, uint64_t *sizep,
-                     int *offset_sizep, struct where *where);
-
-bool read_address_size (struct read_ctx *ctx,
+bool read_address_size (read_ctx *ctx,
                        bool addr_64,
                        int *address_sizep,
-                       struct where const *where);
+                       where const *where);
 
-bool checked_read_uleb128 (struct read_ctx *ctx, uint64_t *ret,
-                          struct where *where, const char *what);
+bool checked_read_uleb128 (read_ctx *ctx, uint64_t *ret,
+                          where *where, const char *what);
 
-bool checked_read_sleb128 (struct read_ctx *ctx, int64_t *ret,
-                          struct where *where, const char *what);
+bool checked_read_sleb128 (read_ctx *ctx, int64_t *ret,
+                          where *where, const char *what);
 
-#ifdef __cplusplus
-}
-#endif
+bool checked_read_leb128 (read_ctx *ctx, form_width_t width, uint64_t *ret,
+                         where *where, const char *what);
 
 #endif//DWARFLINT_CHECKED_READ_HH