These are loop counters which is inherently unsigned. Therefore make
them unsigned. Moreover it also fixes alloc-size-larger-than
error with gcc-13, where malloc can be called with (-1) due to tmp_len
being an int type.
Fixes
| cpumap.c:366:20: error: argument 1 range [
18446744065119617024,
18446744073709551612] exceeds maximum object size
9223372036854775807 [-Werror=alloc-size-larger-than=]
| 366 | tmp_cpus = malloc(tmp_len * sizeof(struct perf_cpu));
| | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Upstream-Status: Submitted [https://lore.kernel.org/linux-perf-users/
20230123211310.127532-1-raj.khem@gmail.com/T/#u]
Signed-off-by: Khem Raj <raj.khem@gmail.com>
Change-Id: I7ecc661339efd49179dd4c1823f4969cee0b0515
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
struct perf_cpu_map *other)
{
struct perf_cpu *tmp_cpus;
- int tmp_len;
- int i, j, k;
+ unsigned int tmp_len;
+ unsigned int i, j, k;
struct perf_cpu_map *merged;
if (perf_cpu_map__is_subset(orig, other))
/* Standard merge algorithm from wikipedia */
i = j = k = 0;
- while (i < orig->nr && j < other->nr) {
+ while (i < (unsigned int)orig->nr && j < (unsigned int)other->nr) {
if (orig->map[i].cpu <= other->map[j].cpu) {
if (orig->map[i].cpu == other->map[j].cpu)
j++;
tmp_cpus[k++] = other->map[j++];
}
- while (i < orig->nr)
+ while (i < (unsigned int)orig->nr)
tmp_cpus[k++] = orig->map[i++];
- while (j < other->nr)
+ while (j < (unsigned int)other->nr)
tmp_cpus[k++] = other->map[j++];
assert(k <= tmp_len);