Skip to content

Commit 9edde81

Browse files
committed
Cleaned up the (U)LEB128 parser
1 parent af16e4b commit 9edde81

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/parser/file/dwarf/leb128.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* CallstackLibrary - Library creating human-readable call stacks.
33
*
4-
* Copyright (C) 2024 mhahnFr
4+
* Copyright (C) 2024 - 2025 mhahnFr
55
*
66
* This file is part of the CallstackLibrary.
77
*
@@ -29,7 +29,7 @@ uint64_t getULEB128(const void* begin, size_t* counter) {
2929

3030
bool more = true;
3131
do {
32-
uint8_t b = *((const uint8_t*) (begin + *counter));
32+
const uint8_t b = *(const uint8_t*) (begin + *counter);
3333
*counter += 1;
3434
result |= (b & 0x7f) << shift;
3535
shift += 7;
@@ -46,13 +46,13 @@ int64_t getLEB128(const void* begin, size_t* counter) {
4646

4747
bool more = true;
4848
do {
49-
uint8_t b = *((const uint8_t*) (begin + *counter));
49+
const uint8_t b = *(const uint8_t*) (begin + *counter);
5050
*counter += 1;
5151
result |= (b & 0x7f) << shift;
5252
shift += 7;
5353
if ((0x80 & b) == 0) {
5454
if (shift < 32 && (b & 0x40) != 0) {
55-
result |= ((uint64_t) ~0 << shift);
55+
result |= (int64_t) ((uint64_t) ~0 << shift);
5656
}
5757
more = false;
5858
}

src/parser/file/dwarf/leb128.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* CallstackLibrary - Library creating human-readable call stacks.
33
*
4-
* Copyright (C) 2024 mhahnFr
4+
* Copyright (C) 2024 - 2025 mhahnFr
55
*
66
* This file is part of the CallstackLibrary.
77
*
@@ -26,9 +26,11 @@
2626
#include <stdint.h>
2727

2828
/**
29-
* @brief Reads an unsigned LEB128 integer from the given memory at the given position.
29+
* @brief Reads an unsigned LEB128 integer from the given memory at the given
30+
* position.
3031
*
31-
* The given memory position points to the first byte after the read number once this function returns.
32+
* The given memory position points to the first byte after the read number
33+
* once this function returns.
3234
*
3335
* @param begin the memory pointer
3436
* @param counter the memory position
@@ -37,16 +39,16 @@
3739
uint64_t getULEB128(const void* begin, size_t* counter);
3840

3941
/**
40-
* @brief Reads a signed LEB128 integer from the given memory at the given position.
42+
* @brief Reads a signed LEB128 integer from the given memory at the given
43+
* position.
4144
*
42-
* The given memory position points to the first byte after the read number once this function returns.
45+
* The given memory position points to the first byte after the read number
46+
* once this function returns.
4347
*
4448
* @param begin the memory pointer
4549
* @param counter the memory position
4650
* @return the deducted number
4751
*/
4852
int64_t getLEB128(const void* begin, size_t* counter);
4953

50-
51-
5254
#endif /* leb128_h */

0 commit comments

Comments
 (0)