【发布时间】:2015-11-20 16:08:25
【问题描述】:
此代码在运行时在 else 中生成错误:
不存在 *** `./a.out' 中的错误:malloc(): smallbin 双链表已损坏:0x09faed58 *** 中止(核心转储)
bool fileExists(char *file) {
if (access(file, F_OK) != -1) {
return true;
} else {
return false;
}
}
void CopyPaste() {
char *fileName = basename(path);
char *c = strcat(dest, "/");
char *newPath = strcat(c, fileName);
if (fileExists(newPath)) {
printf("exists\n");
} else {
printf("non exists\n");
}
}
如果我像这样更改连接代码:
char *newPath = strcat(strcat(dest,"/"),fileName);
它会产生这个不同的错误:
`./a.out' 中的错误:损坏的双链表
可能是什么问题?
【问题讨论】:
-
您的工作环境如何?
-
ubuntu,使用gtk库的C程序
-
你有什么问题?
-
我找不到问题并解决它!!!!
-
strcat将第二个参数复制到第一个给定的缓冲区。strcat(dest, "/")和strcat(strcat(dest, "/"), fileName);看起来很可疑。dest在哪里以及如何定义? (顺便说一句,您真的应该在 Google 上搜索“C 格式约定”并遵循其中的一些原则。您的代码很难阅读。)
标签: c