冷曦_sole 2015-04-10 13:44 采纳率: 0%
浏览 808

solaris下编译的程序执行是出现段错误

编译器版本
Reading specs from /usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/specs
Configured with: /sfw10/builds/build/sfw10-patch/usr/src/cmd/gcc/gcc-3.4.3/configure --prefix=/usr/sfw

--with-as=/usr/ccs/bin/as --without-gnu-as --with-ld=/usr/ccs/bin/ld --without-gnu-ld --enable-

languages=c,c++ --enable-shared
Thread model: posix
gcc version 3.4.3 (csl-sol210-3_4-branch+sol_rpath)

test.h:
#include
#include
#include
#include
#include
#include
#include
#define MAX_DATE_STR_LEN 30
#define SECONDS_PER_DAY 3600 * 24
#define PATH_TOKEN "/"
#define FILE_TYPE_DIR 0
#define FILE_TYPE_OTHER 1
#define FILE_TYPE_NORMAL_FILE 2
int const FILETYPECOUNT=6 ;
using namespace std;
using std::vector;
using std::string;
struct FileInfoSole{
string Name;
string Path;
string FullPath;
long FileId;
int Result;
int Reason;
string ReasonDesc;
int Type;
long Size;
string CreateTime;
string ErrFile;
string TmpErrFile;
string FileType;
};
typedef vector FileListSole;

test.cpp:
#include "test.h"
using namespace std;
int GetFileListSole(string dir, FileListSole &fileList,string substr, int flag);
string tttypes[FILETYPECOUNT]={"CUST","USER","RED","HT","LT","MH"};
int main(){
string dir="./so/";
FileListSole fileList;
string substr;
GetFileListSole(dir,fileList,substr,0);
return 0;
}
int GetFileListSole(string dir, FileListSole &fileList,string substr, int flag){
DIR *pDir = NULL;
if ( ( pDir = opendir(dir.c_str()) ) == NULL ){
return false;
}
int retCode = 0;
FileInfoSole fileInfoSole;
//int solearr[200];
cout<<"link sole"<<endl;
cout<<fileInfoSole.Name<<endl;
cout<<fileInfoSole.Name<<endl;
cout<<fileInfoSole.Name<<endl;
struct dirent entry;
struct dirent *result;
cout<<"4"<<fileInfoSole.Name<<endl;
//for( retCode = readdir_r( pDir, &entry, &result ); result != NULL && 0 == retCode; retCode =

readdir_r( pDir, &entry, &result ) )
retCode = readdir_r( pDir, &entry, &result );
for(int i=0 ;i< 4;i++)
{
retCode = readdir_r( pDir, &entry, &result );
cout<<"5"<<fileInfoSole.Name<<endl;//循环第一次时,程序在这个地方蹦会了,出现段错误,郁闷彻底,求大

侠帮助
if( strcmp( entry.d_name, "." ) == 0 ||strcmp( entry.d_name, "..") == 0)
{
continue;
}
cout<<"testa"<<endl;
cout<<fileInfoSole.Name<<endl;
cout<<"---"<<endl;
fileInfoSole.Name = entry.d_name;
// cout<<fileInfoSole.Name<<endl;
cout<<"testb"<<endl;
if (substr!="")
{
if (fileInfoSole.Name.find(substr)==string::npos)
{
//printf("%s\n",fileInfoSole.Name.c_str());
continue;
}
else
{
//printf("%s\n",fileInfoSole.Name.c_str());
fileInfoSole.FileType=substr;
}
}else
{
fileInfoSole.FileType=string("");
for(int k=0;k<FILETYPECOUNT;k++)
{
if (fileInfoSole.Name.find(tttypes[k])!=string::npos)
{
fileInfoSole.FileType=string(tttypes[k]);
break;
}
}
}
//printf("%s\n",fileInfoSole.Name.c_str());
fileInfoSole.Path = dir;
fileInfoSole.FullPath.clear();
fileInfoSole.FullPath.append(dir).append(PATH_TOKEN).append(entry.d_name);

        //GetFileInfo( fileInfoSole );
         if ( FILE_TYPE_NORMAL_FILE == fileInfoSole.Type ){
             //fileList.push_back(fileInfoSole);
         }

         if ( FILE_TYPE_DIR == fileInfoSole.Type )
         {
            if (flag)
            {
                GetFileListSole(fileInfoSole.FullPath,fileList,substr, flag);
            }
         }
}
closedir(pDir);
cout<<"over"<<endl;
return true;

}

so文件夹:
-bash-3.2$ ls -l so
total 0
-rw-r--r-- 1 bill bill 0 Apr 10 18:30 fileiiiiiiiiiiiiii
执行程序:
-bash-3.2$ ./a.out
link sole

4
5
Segmentation Fault (core dumped)
-bash-3.2$
我就想问程序到cout<<"5"<<fileInfoSole.Name<<endl;个语句是报段错误,我猜测是系统调用导致的内存泄露,于是

我在程序
FileInfoSole fileInfoSole;和struct dirent entry; 之间放了一个int solearr[200];
数组,就不会出现段错误了或者把so文件夹下的文件"fileiiiiiiiiiiiiii"改成短一点的"file"的时就不会出现段错误

了,请问这是什么原因导致的,有什么更好的办法解决这个问题,越详细细越好,等代大神解决.....

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作