找出数组复制分配里的 bug

来自 C 动态内存管理
C23 (GCC 13.3.0) 进阶 4分钟 找出 1处问题

找出这个生成的数组复制函数中的大小错误。

C
#include <stddef.h>
#include <stdlib.h>

int *copy_readings(const int *source, size_t count) {
    int *copy = (int *)malloc(count * sizeof *copy);
    if (copy == NULL) {
        return NULL;
    }
    for (size_t index = 0; index < count; ++index) {
        copy[index] = source[index];
    }
    return copy;
}
在试验场中打开
报告错误