From: Dmitry V. Levin Date: Sat, 12 Nov 2016 00:36:01 +0000 (+0000) Subject: syscall.c: introduce reallocate_vec function X-Git-Tag: v4.15~142 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5e33997559a1d396f2e8174d037367d6eba939e7;p=strace syscall.c: introduce reallocate_vec function This might be needed later to implement syscall fault injection. * syscall.c (reallocate_vec): New function. (reallocate_qual): Use it. --- diff --git a/syscall.c b/syscall.c index f69132a9..1f621f5d 100644 --- a/syscall.c +++ b/syscall.c @@ -390,15 +390,22 @@ static const struct qual_options { }; static void -reallocate_qual(const unsigned int n) +reallocate_vec(void **vec, unsigned int old_nmemb, + size_t size, unsigned int new_nmemb) { - unsigned p; - qualbits_t *qp; - for (p = 0; p < SUPPORTED_PERSONALITIES; p++) { - qp = qual_vec[p] = xreallocarray(qual_vec[p], n, - sizeof(qualbits_t)); - memset(&qp[num_quals], 0, (n - num_quals) * sizeof(qualbits_t)); + unsigned int p; + + for (p = 0; p < SUPPORTED_PERSONALITIES; ++p) { + vec[p] = xreallocarray(vec[p], new_nmemb, size); + memset(vec[p] + size * old_nmemb, 0, + (new_nmemb - old_nmemb) * size); } +} + +static void +reallocate_qual(const unsigned int n) +{ + reallocate_vec((void **) qual_vec, num_quals, sizeof(qualbits_t), n); num_quals = n; }