运行时附加的下面的 C 代码给出了错误
summary: malloc.c:3074: 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.
在每次调用 malloc(21) 时;(见下文)。有人可以解释为什么吗?我已经尝试了我能想到的所有可能的事情,但仍然失败。
文件:summary.c
/*
* File: summary.c
* Author: Maxim Veksler
*
* Created on December 4, 2009, 3:09 AM
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "manipulation.h"
/*
* Main for Maman 12, task 1 : Array summary utility
*/
int main(int argc, char** argv) {
/*STUB*/
char str[100];
strcpy(str, "3 5 234 11 77 44 5");
/*STUB*/
int resultsSize;
int* results;
int* aggregated;
results = parseInput(str, &resultsSize);
aggregatedArray((int*)NULL, (int)NULL);
return 0;
}
文件操作.c
/*
* File: manipulation.c
* Author: Maxim Veksler
*
* Created on December 4, 2009, 3:09 AM
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
/*
* Parse the input from user, dynamically allocate memory to the maximum
* possible requirment. Then convert the array of string tokens into an
* simple array of integers.
*/
int* parseInput(char* input, int* nOfResults) {
/* Allocate memory by the maximum possibly required size for int... */
int *results = (int*) malloc(strlen(input));
int* insertIterator = results;
char* pch;
/* We trash the user input, but it's cool - Worthless as usual. */
pch = strtok(input,"\t ,.-");
*nOfResults = 0;
while(pch != NULL) {
(*nOfResults)++;
*insertIterator = atoi(pch);
insertIterator++;
pch = strtok(NULL, "\t ,.-");
}
return results;
}
/*
* Summary the values given in the int array and return adress to new array
* containing an increasin sum of the values.
*/
int* aggregatedArray(int* inputArray, int size) {
int* results;
malloc(20);
malloc(21);
}
编辑请考虑到这个代码是一个精简的版本,它被带到这里来显示问题。我已经删除了所有不相关的部分。