Commit 2d12117c authored by tqcq's avatar tqcq
Browse files

fix cursor crash

parent 60ff77ec
Loading
Loading
Loading
Loading
+141 −146
Original line number Diff line number Diff line
@@ -4,8 +4,8 @@

#include "internal.hh"

#include <stdexcept>
#include <cstring>
#include <stdexcept>

using namespace std;

@@ -22,8 +22,7 @@ cursor::sleb128()
        result |= (uint64_t) (byte & 0x7f) << shift;
        shift += 7;
        if ((byte & 0x80) == 0) {
                        if (shift < sizeof(result)*8 && (byte & 0x40))
                                result |= -((uint64_t)1 << shift);
            if (shift < sizeof(result) * 8 && (byte & 0x40)) result |= -((uint64_t) 1 << shift);
            return result;
        }
    }
@@ -91,8 +90,9 @@ cursor::string(std::string &out)
{
    size_t size;
    const char *p = this->cstr(&size);
        out.resize(size);
        memmove(&out.front(), p, size);
    // out.resize(size);
    // memmove(&out.front(), p, size);
    out = std::string(p, p + size);
}

const char *
@@ -100,12 +100,9 @@ cursor::cstr(size_t *size_out)
{
    // Scan string size
    const char *p = pos;
        while (pos < sec->end && *pos)
                pos++;
        if (pos == sec->end)
                throw format_error("unterminated string");
        if (size_out)
                *size_out = pos - p;
    while (pos < sec->end && *pos) pos++;
    if (pos == sec->end) throw format_error("unterminated string");
    if (size_out) *size_out = pos - p;
    pos++;
    return p;
}
@@ -179,13 +176,11 @@ cursor::skip_form(DW_FORM form)
    case DW_FORM::sdata:
    case DW_FORM::udata:
    case DW_FORM::ref_udata:
                while (pos < sec->end && (*(uint8_t*)pos & 0x80))
                        pos++;
        while (pos < sec->end && (*(uint8_t *) pos & 0x80)) pos++;
        pos++;
        break;
    case DW_FORM::string:
                while (pos < sec->end && *pos)
                        pos++;
        while (pos < sec->end && *pos) pos++;
        pos++;
        break;