mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 12:54:27 +00:00
libthread_db: unsign map_len and use reallocarray(3).
Lengths are not negative, so map_len should be unsigned. Unsign the corresponding indexes too and bring a small use of reallocarray(3). Reorder the memset to be consistent with the realloc: it appears we were only clearing half the memory in pt_map_thread(). MFC after: 2 weeks
This commit is contained in:
parent
2d445fb18c
commit
1f2b051d84
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=317200
|
@ -74,7 +74,8 @@ pt_map_thread(const td_thragent_t *const_ta, psaddr_t pt, enum pt_type type)
|
||||||
{
|
{
|
||||||
td_thragent_t *ta = __DECONST(td_thragent_t *, const_ta);
|
td_thragent_t *ta = __DECONST(td_thragent_t *, const_ta);
|
||||||
struct pt_map *new;
|
struct pt_map *new;
|
||||||
int i, first = -1;
|
int first = -1;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
/* leave zero out */
|
/* leave zero out */
|
||||||
for (i = 1; i < ta->map_len; ++i) {
|
for (i = 1; i < ta->map_len; ++i) {
|
||||||
|
@ -94,12 +95,12 @@ pt_map_thread(const td_thragent_t *const_ta, psaddr_t pt, enum pt_type type)
|
||||||
ta->map_len = 20;
|
ta->map_len = 20;
|
||||||
first = 1;
|
first = 1;
|
||||||
} else {
|
} else {
|
||||||
new = realloc(ta->map,
|
new = reallocarray(ta->map, ta->map_len,
|
||||||
sizeof(struct pt_map) * ta->map_len * 2);
|
2 * sizeof(struct pt_map));
|
||||||
if (new == NULL)
|
if (new == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
memset(new + ta->map_len, '\0', sizeof(struct pt_map) *
|
memset(new + ta->map_len, '\0', ta->map_len *
|
||||||
ta->map_len);
|
2 * sizeof(struct pt_map));
|
||||||
first = ta->map_len;
|
first = ta->map_len;
|
||||||
ta->map = new;
|
ta->map = new;
|
||||||
ta->map_len *= 2;
|
ta->map_len *= 2;
|
||||||
|
@ -1047,7 +1048,7 @@ pt_thr_sstep(const td_thrhandle_t *th, int step)
|
||||||
static void
|
static void
|
||||||
pt_unmap_lwp(const td_thragent_t *ta, lwpid_t lwp)
|
pt_unmap_lwp(const td_thragent_t *ta, lwpid_t lwp)
|
||||||
{
|
{
|
||||||
int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < ta->map_len; ++i) {
|
for (i = 0; i < ta->map_len; ++i) {
|
||||||
if (ta->map[i].type == PT_LWP && ta->map[i].lwp == lwp) {
|
if (ta->map[i].type == PT_LWP && ta->map[i].lwp == lwp) {
|
||||||
|
|
|
@ -77,7 +77,7 @@ struct td_thragent {
|
||||||
int thread_off_sigmask;
|
int thread_off_sigmask;
|
||||||
int thread_off_sigpend;
|
int thread_off_sigpend;
|
||||||
struct pt_map *map;
|
struct pt_map *map;
|
||||||
int map_len;
|
unsigned int map_len;
|
||||||
};
|
};
|
||||||
|
|
||||||
void pt_md_init(void);
|
void pt_md_init(void);
|
||||||
|
|
Loading…
Reference in a new issue