简体   繁体   English

tester.exe中0x00b21840处未处理的异常:0xC0000005:访问冲突读取位置0x00000000

[英]Unhandled exception at 0x00b21840 in tester.exe: 0xC0000005: Access violation reading location 0x00000000

BOOL bLoadActions()
{
    int iIndex = 0;
    int iRows;
    int iFields;
    MYSQL_ROW myRow;
    MYSQL_FIELD* field [200];

    for (int a = 0; a < 200; a++)
        field[a] = NULL;

mysql_query(con, "SELECT * FROM `cq_action`;");
res= mysql_store_result(con);
if ((iRows = (int)mysql_num_rows(res)) > 0)
{
    iFields = (WORD)mysql_num_fields(res);
    for(int b = 0; b < iRows; b++)
    {
        myRow = mysql_fetch_row(res);//<=== error here
        mysql_field_seek(res, 0);
        for(int f = 0; f < iFields; f++)
        {
            field[f] = mysql_fetch_field(res);
            if(field[f]) {
            if(!strcmp(field[f]->name, "id"))
            {
                iIndex++;
                m_pActionList[iIndex] = new class CAction;
                m_pActionList[iIndex]->id = atoi(myRow[f]);
                m_pActionList[iIndex]->index = iIndex;
            }
            else if(!strcmp(field[f]->name, "param"))
            {
                m_pActionList[iIndex]->param = new char[strlen(myRow[f])+1];
                m_pActionList[iIndex]->param[strlen(myRow[f])] = 0;
                memcpy(m_pActionList[iIndex]->param, myRow[f], strlen(myRow[f]));
            }
            else if(!strcmp(field[f]->name, "type"))
                m_pActionList[iIndex]->type = atoi(myRow[f]);
            else if(!strcmp(field[f]->name, "id_next"))
                m_pActionList[iIndex]->idnext = atoi(myRow[f]);
            else if(!strcmp(field[f]->name, "id_nextfail"))
                m_pActionList[iIndex]->idfail = atoi(myRow[f]);
            else if(!strcmp(field[f]->name, "data"))
                m_pActionList[iIndex]->data = atoi(myRow[f]);
            }
            else{
                if(field[f]=NULL)
                    cout<<"error"<<endl;
            }
        }
    }
}

return 0;

} idk every thing seems good.... but i get this error } idk一切似乎都很好。...但是我得到这个错误

Unhandled exception at 0x00b21840 in tester.exe: 0xC0000005: Access violation reading location 0x00000000.

after the edit the errors happens here myRow = mysql_fetch_row(res);//<=== error here 编辑后,错误发生在这里myRow = mysql_fetch_row(res);//<=== error here

It means one of the pointers is null when it is dereferenced. 这意味着在取消引用时指针之一为空。 Attach a debugger, it will tell you which line the error occurs on. 附加一个调试器,它将告诉您错误发生在哪一行。

As others said, you're most likely dereferencing a NULL pointer coming from mysql_fetch_field . 正如其他人所说,您很可能会取消引用来自mysql_fetch_fieldNULL指针。 You should change your code to something like this: 您应该将代码更改为以下内容:

            for(int f = 0; f < m_fields; f++){ 
                field[f] = mysql_fetch_field(res);
                if(field[f]) {
                  if(!strcmp(field[f]->name, "id")){// <= error happens here
                      iIndex++;
                      m_pNpcList[iIndex] = new class CNpc;
                      m_pNpcList[iIndex]->m_iID = atoi(row[f]);
                  }
                } else {
                  //field[f] is NULL, do some error handling here
                }
            }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NVIDIA未处理的异常,位于0x002a2da2中 <work.exe> 0xC0000005:访问冲突读取位置0x00000000 - NVIDIA Unhandled exception at 0x002a2da2 in <work.exe>0xC0000005: Access violation reading location 0x00000000 模拟Clock.exe中0x00BF57F9处未处理的异常:0xC0000005:访问冲突读取位置0x00000000 - Unhandled exception at 0x00BF57F9 in Analog Clock.exe: 0xC0000005: Access violation reading location 0x00000000 application.exe中0x0872340b(CAN.dll)的未处理异常:0xC0000005:访问冲突读取位置0x00000000 - Unhandled exception at 0x0872340b (CAN.dll) in application.exe: 0xC0000005: Access violation reading location 0x00000000 0xC0000005:访问冲突读取位置0x00000000 - 0xC0000005: Access violation reading location 0x00000000 0xC0000005:访问冲突读取位置0x00000000 - 0xC0000005: Access violation reading location 0x00000000 在0xC0000005中的0x6ececafa出现未处理的异常:访问冲突写入位置0x00000000 - Unhandled Exception as at 0x6ececafa in 0xC0000005 : Access violation writing location 0x00000000 Engine.exe中0x00000000的未处理异常:0xC0000005:访问冲突 - Unhandled exception at 0x00000000 in Engine.exe: 0xC0000005: Access violation Metrics_Alpha.exe 中 0x78F90870 (ucrtbased.dll) 处的未处理异常:0xC0000005:访问冲突读取位置 0x00000000 - Unhandled exception at 0x78F90870 (ucrtbased.dll) in Metrics_Alpha.exe: 0xC0000005: Access violation reading location 0x00000000 在 Project0_opengl.exe 中的 0x00000000 处抛出异常:0xC0000005:访问冲突执行位置 0x00000000 - Exception thrown at 0x00000000 in Project0_opengl.exe: 0xC0000005: Access violation executing location 0x00000000 在 CobwebDiagram.exe 中的 0x00000000 处引发异常:0xC0000005:访问冲突执行位置 0x00000000 - Exception thrown at 0x00000000 in CobwebDiagram.exe: 0xC0000005: Access violation executing location 0x00000000
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM