使用gcc-4.8.4检测到堆栈粉碎,但没有用4.9.1检测到

时间:2017-03-27 13:11:05

标签: c linux gcc stack

我用C编写了一个程序(下面的代码片段见最后评论)编译 与gcc。在程序死后一段时间执行,并带有消息

*检测到堆栈粉碎*

Valgrind没有报告任何与此相关的问题。 使用gdb逐步接近故障点我得到:

... 107返回(nread); (GDB) 108} (GDB) *堆栈粉碎检测* :/ home / micb / bin / fogal已终止

编程接收信号SIGABRT,已中止。 __GI_raise中的0x00007ffff7745cc9(sig = sig @ entry = 6)at ../nptl/sysdeps/unix/sysv/linux/raise.c:56 56 ../nptl/sysdeps/unix/sysv/linux/raise.c:没有这样的文件或目录。

程序终止,信号SIGABRT,Aborted。

函数终止时发生错误... " return(nread)",其中nread是本地整数,是最后一个语句 这是执行的,就在主循环中的函数之后,就是a printf()+ fflush语句不再执行...

有趣的是:当我使用gcc-4.8.4编译时,我收到此错误 但如果我使用完全相同的源和程序输入不同 有gcc-4.9.2的机器错误不会发生...

除了安装之外,还有什么方法可以解决这个问题 一个不同的C编译器?

欢呼声, 迈克尔

代码:

int fitness(const char* id, t_genotype* genome, t_topology_size* size,
            t_topology* top, double* qme, int n_qme) {

      char topfilename[124];
      char tprfilename[124];
      char enefilename[124];
      char logfilename[124];
      char xvgfilename[124];
      char mdpfilename[124];

      char command[124];
      FILE* fxvg;
      double dummy;
      double potential;
      int nread;
      int i;
      double rmsd, sumsq, e0gmx;
      char fnam[124];
      int ret;
      int maxtimeformdrun = (int)((double)(genome->length)/10.0);

      sprintf(topfilename, "top-%s.top", id);
      sprintf(tprfilename, "top-%s.tpr", id);
      sprintf(logfilename, "top-%s.log", id);
      sprintf(enefilename, "top-%s.edr", id);
      sprintf(xvgfilename, "top-%s.xvg", id);
      sprintf(mdpfilename, "top-%s.mdp", id);

      if(write_mod_top(topfilename,size,top,genome)!=0)
        error_msg("Can not write modified topology file");

      sprintf(command, "gmx grompp -f md0.mdp -c onesis.pdb -p %s -o %s -po %s > err1 2>&1", topfilename, tprfilename, mdpfilename);
      if(system(command)!=0) error_msg("gmx grompp failed");

      sprintf(command, "timeout %d gmx mdrun -rerun c-all.trr -s %s -e %s -g %s > err2 2>&1", 
              maxtimeformdrun, tprfilename,enefilename,logfilename);
      ret=system(command);
      if(ret!=0) {
        if(ret=124) {
          fprintf(stderr,"ERROR \"%s\"\n", command);
          fprintf(stderr,"took more than %d seconds\n", maxtimeformdrun);
          fprintf(stderr,"presumably this got stuck, returning a fitness of 1.0e+12");
          genome->fitness = 1.0e+12;
          return(0);
        } else {
          fprintf(stderr,"was trying %s\n", command);
          error_msg("gmx mdrun failed");
        }
      }

      sprintf(command, "cat eterm | gmx energy -f %s -o %s -xvg none > err3 2>&1 ", enefilename,xvgfilename);
      if(system(command)!=0) error_msg("gmx energy failed");

      if((fxvg=fopen(xvgfilename, "r"))==NULL) error_msg("cannot open xvg file");

      nread=0;
      sumsq=0.0;

      while(fscanf(fxvg,"%lf %lf", &dummy, &potential)==2) {

        if(nread==n_qme) error_msg("number of gmx energies larger than n_qme");
        if(nread==0) e0gmx = potential;
        potential -= e0gmx;
        sumsq+=(qme[nread]-potential)*(qme[nread]-potential);
        nread++;
      }

      fclose(fxvg);

      sprintf(command, "rm -f err1 err2 err3 %s %s %s %s %s %s", 
              topfilename, tprfilename, enefilename, logfilename, xvgfilename, mdpfilename);
      if(system(command)!=0) error_msg("removal of gmx files failed");

      genome->fitness = sqrt(sumsq/(double)nread);

      return(nread); // ERROR happens exactly here once the char string in "id" exceeds a certain length (which is MUCH shorter than the allocated length in the calling main function: "char id[256]"
    }

0 个答案:

没有答案