mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-27 03:21:32 +03:00
Merge pull request #13034 from poettering/memdup-suffix0-multiply-fixo
memdup_suffix0_multiply fix
This commit is contained in:
commit
5978345750
@ -112,7 +112,9 @@ _alloc_(2, 3) static inline void *memdup_multiply(const void *p, size_t size, si
|
||||
return memdup(p, size * need);
|
||||
}
|
||||
|
||||
_alloc_(2, 3) static inline void *memdup_suffix0_multiply(const void *p, size_t size, size_t need) {
|
||||
/* Note that we can't decorate this function with _alloc_() since the returned memory area is one byte larger
|
||||
* than the product of its parameters. */
|
||||
static inline void *memdup_suffix0_multiply(const void *p, size_t size, size_t need) {
|
||||
if (size_multiply_overflow(size, need))
|
||||
return NULL;
|
||||
|
||||
|
@ -56,20 +56,20 @@ static void test_GREEDY_REALLOC(void) {
|
||||
}
|
||||
|
||||
static void test_memdup_multiply_and_greedy_realloc(void) {
|
||||
int org[] = {1, 2, 3};
|
||||
static const int org[] = { 1, 2, 3 };
|
||||
_cleanup_free_ int *dup;
|
||||
int *p;
|
||||
size_t i, allocated = 3;
|
||||
|
||||
dup = (int*) memdup_suffix0_multiply(org, sizeof(int), 3);
|
||||
dup = memdup_suffix0_multiply(org, sizeof(int), 3);
|
||||
assert_se(dup);
|
||||
assert_se(dup[0] == 1);
|
||||
assert_se(dup[1] == 2);
|
||||
assert_se(dup[2] == 3);
|
||||
assert_se(*(uint8_t*) (dup + 3) == (uint8_t) 0);
|
||||
assert_se(((uint8_t*) dup)[sizeof(int) * 3] == 0);
|
||||
free(dup);
|
||||
|
||||
dup = (int*) memdup_multiply(org, sizeof(int), 3);
|
||||
dup = memdup_multiply(org, sizeof(int), 3);
|
||||
assert_se(dup);
|
||||
assert_se(dup[0] == 1);
|
||||
assert_se(dup[1] == 2);
|
||||
|
Loading…
Reference in New Issue
Block a user