mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-05 09:17:44 +03:00
login: fix pos-array allocation
GREEDY_REALLOC takes a pointer to the real size, not the array-width as argument. Therefore, our array is currently way to small to keep the seat positions. Introduce GREEDY_REALLOC0_T() as typed version of GREEDY_REALLOC and store the array-width instead of array-size.
This commit is contained in:
parent
23fae27185
commit
a1937e679f
@ -475,7 +475,7 @@ void seat_claim_position(Seat *s, Session *session, unsigned int pos) {
|
|||||||
if (seat_has_vts(s))
|
if (seat_has_vts(s))
|
||||||
pos = session->vtnr;
|
pos = session->vtnr;
|
||||||
|
|
||||||
if (!GREEDY_REALLOC0(s->positions, s->position_count, pos + 1))
|
if (!GREEDY_REALLOC0_T(s->positions, s->position_count, pos + 1))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
seat_evict_position(s, session);
|
seat_evict_position(s, session);
|
||||||
|
@ -723,6 +723,15 @@ void* greedy_realloc0(void **p, size_t *allocated, size_t need);
|
|||||||
#define GREEDY_REALLOC0(array, allocated, need) \
|
#define GREEDY_REALLOC0(array, allocated, need) \
|
||||||
greedy_realloc0((void**) &(array), &(allocated), sizeof((array)[0]) * (need))
|
greedy_realloc0((void**) &(array), &(allocated), sizeof((array)[0]) * (need))
|
||||||
|
|
||||||
|
#define GREEDY_REALLOC0_T(array, count, need) \
|
||||||
|
({ \
|
||||||
|
size_t _size = (count) * sizeof((array)[0]); \
|
||||||
|
void *_ptr = GREEDY_REALLOC0((array), _size, (need)); \
|
||||||
|
if (_ptr) \
|
||||||
|
(count) = _size / sizeof((array)[0]); \
|
||||||
|
_ptr; \
|
||||||
|
})
|
||||||
|
|
||||||
static inline void _reset_errno_(int *saved_errno) {
|
static inline void _reset_errno_(int *saved_errno) {
|
||||||
errno = *saved_errno;
|
errno = *saved_errno;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user