#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#define PASSES 100000
char *rline(int maxChars, FILE *stream) {
char *buf = (char *)malloc(maxChars);
fscanf(stream, "%s", buf);
int len = strlen(buf);
char *str = (char *)malloc(len);
strcpy(str, buf);
free(buf);
return str;
}
int main() {
time_t seed = time(NULL);
FILE *in2 = fopen("strings.txt", "r");
char **index2 = (char **) calloc(PASSES, sizeof(char *));
srand(seed);
printf("%d\n", (int)seed);
for (int j = 0; j < PASSES; j++)
index2[j] = rline(65, in2);
printf("Array 2 created!\n");
return 0;
}
На какой-то итерации цикла, программа падает, и выдает совершенно неведомую ошибку: 123: malloc.c:2369: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed. Аварийный останов
Хз что с этим делать, программа должна считать из файла строки в массив. Как это лечить? Вот тестовый файл: rghost