why does this code give me a buffer overflow error?
int len = 1;
const User *current = curr;

while (current != NULL) {
    len += strlen(current->name) + 2;
    current = current->next;
}

char *buf = malloc(sizeof(char) * len);
int index = 0;
int add = 0;

while (curr != NULL) {
    add = snprintf(buf + index, len - index, "%s\r\n", curr->name);

    if (add >= len - len) {
        // buffer overflow (shouldn't happen though)
        perror("Buffer overflow");
        exit(1);
    }
    index += add;
    curr = curr->next;
}
buf[len - 1] = '\0';
return buf;