• Unhandled exception at 0x........ in XXXX.exe: 0xC0000005:错误


    对于C++初学者或粗心者,很容易犯如下图所示错误:
     
     
    那么该错误是由什么造成的呢?
     
    答案无疑只有一个,即:读取了本该没有的值或者地址。
     
    那么如何解决呢?
     
    第一件事,检查下你传入的参数是否合法;
    第二件事,若malloc了一块内存,必须记得free;
    第三件事,你是否赋值了已经溢出的值或地址。
     
    举例说明:
     
    [cpp] view plain copy
     
     print?
    1. pOrg = pcPicYuvOrg->getLumaAddr();  
    2.     for( y = 0; y < height-1; y++ )  
    3.     {  
    4.         for( x = 0; x < width-1; x++ )  
    5.         {  
    6.             Pel A[4];  
    7.             //2x2  
    8.             A[0]=pOrg[x];   A[1]=pOrg[x+1];   
    9.             A[2]=(pOrg+stride)[x];  A[3]=(pOrg+stride)[x+1];  
    10.   
    11.             if( A[0]==255 && A[1]==255 && A[2]==255 && A[3]==255 )  
    12.             {  
    13.                 pOrg[x] = 255;  pOrg[x+1] = 255;  
    14.                 (pOrg+stride)[x] = 255; (pOrg+stride)[x+1] = 255;  
    15.             }  
    16.             else  
    17.             {  
    18.                 pOrg[x] = 0;    pOrg[x+1] = 0;  
    19.                 (pOrg+stride)[x] = 0;   (pOrg+stride)[x+1] = 0;  
    20.             }  
    21.             x += 1;  
    22.         }  
    23.         pOrg += 2*stride;  
    24.     }  

    此代码就会出现上图所示错误。那么如何解决呢?
     
    [cpp] view plain copy
     
     print?
    1. pOrg = pcPicYuvOrg->getLumaAddr();  
    2.     for( y = 0; y < height/2; y++ )  
    3.     {  
    4.         for( x = 0; x < width-1; x++ )  
    5.         {  
    6.             Pel A[4];  
    7.             //2x2  
    8.             A[0]=pOrg[x];   A[1]=pOrg[x+1];   
    9.             A[2]=(pOrg+stride)[x];  A[3]=(pOrg+stride)[x+1];  
    10.   
    11.             if( A[0]==255 && A[1]==255 && A[2]==255 && A[3]==255 )  
    12.             {  
    13.                 pOrg[x] = 255;  pOrg[x+1] = 255;  
    14.                 (pOrg+stride)[x] = 255; (pOrg+stride)[x+1] = 255;  
    15.             }  
    16.             else  
    17.             {  
    18.                 pOrg[x] = 0;    pOrg[x+1] = 0;  
    19.                 (pOrg+stride)[x] = 0;   (pOrg+stride)[x+1] = 0;  
    20.             }  
    21.             x += 1;  
    22.         }  
    23.         pOrg += 2*stride;  
    24.     }  

    很明显,错误的原因在于:赋值了已经溢出的值。
     
    若以后遇到类似问题,可以逐步检查上述提出的“三件事情”即可。
  • 相关阅读:
    Apache安装与属性配置
    Web服务及http协议
    转-httpd 2.4.4 + mysql-5.5.28 + php-5.4.13编译安装过程
    LAMP理论整理
    Rhel6-csync配置文档
    转载Eclipse中Maven WEB工程tomcat项目添加调试
    转载--eclipse git插件安装
    l连接远程桌面
    Aphache VFS
    JMS-activeMQ
  • 原文地址:https://www.cnblogs.com/zsq1993/p/6067452.html
Copyright © 2020-2023  润新知