【问题标题】:corruption of the heap, error in C [closed]堆损坏,C中的错误[关闭]
【发布时间】:2017-09-12 04:18:45
【问题描述】:

好吧我不需要解释太多,这个函数在我一直标记的那一行得到这个错误,只有在这个函数中有内存分配,请帮我找出问题所在......(阅读这里有一些其他主题,但没有任何帮助我解决它) 错误:“Windows 已在 sapProject.exe 中触发断点。

这可能是由于堆损坏,这表明 sapProject.exe 或其已加载的任何 DLL 中存在错误。 "

void storeTok(char * lexem,int line,enum keywords typeof)
{
    int ind;
    if(tokens.size%100==0)
    {
    if(tokens.size==0)
    {
    tokens.ptrInd=-1;
    tokens.first=(node*)malloc(sizeof(node));
    tokens.first->back = NULL;
    tokens.first->next = NULL;
    tokens.last=tokens.first;
    }
    else
    {
    node * nodenz=(node*)malloc(sizeof(node)); /error is here
    nodenz->back = tokens.last;
    nodenz->next = NULL;
    tokens.last->next=nodenz;
    tokens.last=tokens.last->next;
    tokens.last=nodenz;
    }
    }

    // general




ind=tokens.size-(tokens.size/100)*100;
tokens.last->tokens[ind].type=typeof;
tokens.last->tokens[ind].linen=line;
tokens.last->tokens[ind].lexema=lexem;
tokens.size++;
}

谢谢!

编辑(除了这个,还有一个标题(就是这样..):

typedef struct token
{
    char * lexema ;
    int linen;
    enum keywords type;
}token;

typedef struct node
{
    struct node * next,*back;
    token tokens [50];
}node;

typedef struct LL
{
    struct node * last, *first, * ptr;
    int size,ptrInd;
}LL;

LL tokens;

void storeTok(char * lexem,int line,enum keywords typeof);

主要功能:

void main()
{
    int i;
    for(i=0;i<26;++i)
    {
storeTok("blabla",1,END);
storeTok("sdfasd",1,START);
storeTok("sfadds",1,IF);
storeTok("gvdfd",1,THEN);
storeTok("dfsfd",1,ELSE);
    }
    storeTok("dfsfd",1,EOF_);
}

【问题讨论】:

  • 那我也不解释我的反对意见了。
  • @GhostCat 请解释一下 :) 是不是因为你不喜欢别人提问?
  • 只需阅读随附的消息:您的问题已暂停。
  • 大声笑,如果有人真的需要一个理由,你的缩进让你很难阅读/遵循你的代码。

标签: c debugging heap-memory


【解决方案1】:

那条线可能是受害者。破坏堆的代码在别处。您可以使用 valgrind 之类的工具或类似工具来查找它。 (或者给我们足够的代码来复制错误,我们可以为您追踪它。)

【讨论】:

  • 最好是评论;这样的问题可能会结束。
  • 你不应该在评论中回答这个问题,这回答了这个问题。 (只要有问题。)
  • @DavidSchwartz 添加了其余的代码(它只是一个头文件..)
  • 这不足以复制问题。问题出在其他代码中。
  • @DavidSchwartz 但没有其他代码.....
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-29
  • 2020-04-11
  • 1970-01-01
  • 2011-12-03
  • 2011-08-03
  • 1970-01-01
相关资源
最近更新 更多