Imported Upstream version 1.2
[platform/upstream/libunwind.git] / src / mi / _ReadSLEB.c
1 #include <libunwind.h>
2
3 unw_word_t
4 _ReadSLEB (unsigned char **dpp)
5 {
6   unsigned shift = 0;
7   unw_word_t byte, result = 0;
8   unsigned char *bp = *dpp;
9
10   while (1)
11     {
12       byte = *bp++;
13       result |= (byte & 0x7f) << shift;
14       shift += 7;
15       if ((byte & 0x80) == 0)
16         break;
17     }
18
19   if (shift < 8 * sizeof (unw_word_t) && (byte & 0x40) != 0)
20     /* sign-extend negative value */
21     result |= ((unw_word_t) -1) << shift;
22
23   *dpp = bp;
24   return result;
25 }