| 22 | } |
| 23 | |
| 24 | static int encode(unsigned n, unsigned char *buf) { |
| 25 | int len = 0; |
| 26 | if (n < 128) { |
| 27 | buf[len++] = n & 0x7f; |
| 28 | } else if (n < 16384) { |
| 29 | buf[len++] = ((unsigned char) n & 0x7f) | 0x80; |
| 30 | buf[len++] = ((unsigned char) (n >> 7) & 0x7f); |
| 31 | } else if (n < 2097152) { |
| 32 | buf[len++] = ((unsigned char) n & 0x7f) | 0x80; |
| 33 | buf[len++] = ((unsigned char) (n >> 7 ) & 0x7f) | 0x80; |
| 34 | buf[len++] = ((unsigned char) (n >> 14) & 0x7f); |
| 35 | } else if (n < 268435456) { |
| 36 | buf[len++] = ((unsigned char) n & 0x7f) | 0x80; |
| 37 | buf[len++] = ((unsigned char) (n >> 7 ) & 0x7f) | 0x80; |
| 38 | buf[len++] = ((unsigned char) (n >> 14) & 0x7f) | 0x80; |
| 39 | buf[len++] = ((unsigned char) (n >> 21) & 0x7f); |
| 40 | } else { |
| 41 | printf("invalid dlen_=%u\n", n); |
| 42 | return -1; |
| 43 | } |
| 44 | |
| 45 | return len; |
| 46 | } |
| 47 | |
| 48 | int main(void) { |
| 49 | unsigned char buf[4]; |
no outgoing calls
no test coverage detected
searching dependent graphs…