我不断收到这个 malloc.c 断言失败。我看过其他类似的问题,但似乎找不到解决方案。这是我的代码......我在它出错之前就在现场放置了一个 printf。
int ParseCommand(char *cmd_line, struct command_t *cmd, char **paths)
{
int argc;
char **line_ptr;
char *tmp_name = (char *) malloc(sizeof(MAX_PATH_LEN));
/* Initialization */
line_ptr = &cmd_line;
argc = 0;
cmd->argv[argc] = (char *) malloc(MAX_ARG_LEN);
/* Fill argv[] Array */
while((cmd->argv[argc] = strsep(line_ptr, WHITESPACE)) != NULL) {
cmd->argv[++argc] = (char *) malloc(MAX_ARG_LEN);
}
/* Set The Command Name & argc */
cmd->argc = argc - 1;
tmp_name = LookupPath(cmd->argv, paths);
if(tmp_name == NULL) {
Fatal("Command Not Found!");
}
printf("HERE 4\n");
cmd->name = (char *) malloc(sizeof(tmp_name));
strncpy(cmd->name, tmp_name, MAX_PATH_LEN);
free(tmp_name);
}
错误是:
smallsh: 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.
Aborted (core dumped)
非常感谢您的帮助!