summaryrefslogtreecommitdiff
path: root/src/third_party/unwind/dist/src/mi/_ReadSLEB.c
blob: c041e37a0543f055876a53759e17d8a09193d6bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <libunwind.h>

unw_word_t
_ReadSLEB (unsigned char **dpp)
{
  unsigned shift = 0;
  unw_word_t byte, result = 0;
  unsigned char *bp = *dpp;

  while (1)
    {
      byte = *bp++;
      result |= (byte & 0x7f) << shift;
      shift += 7;
      if ((byte & 0x80) == 0)
        break;
    }

  if (shift < 8 * sizeof (unw_word_t) && (byte & 0x40) != 0)
    /* sign-extend negative value */
    result |= ((unw_word_t) -1) << shift;

  *dpp = bp;
  return result;
}