From: Petr Machata Date: Wed, 6 Oct 2010 18:31:14 +0000 (+0200) Subject: dwarflint: Add checked_read_leb128 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=76a2a05026fc0ac58218f8e377785cf5d11f1a52;p=thirdparty%2Felfutils.git dwarflint: Add checked_read_leb128 - this is similar to read_ctx_read_var - also drop a bunch of C-isms --- diff --git a/dwarflint/checked_read.cc b/dwarflint/checked_read.cc index ced62beac..0c74b42a9 100644 --- a/dwarflint/checked_read.cc +++ b/dwarflint/checked_read.cc @@ -31,6 +31,8 @@ #endif #include +#include + #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); +} diff --git a/dwarflint/checked_read.hh b/dwarflint/checked_read.hh index caeba92d7..316db3696 100644 --- a/dwarflint/checked_read.hh +++ b/dwarflint/checked_read.hh @@ -27,28 +27,24 @@ #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