对于C++初学者或粗心者,很容易犯如下图所示错误:
 
 
那么该错误是由什么造成的呢?
 
答案无疑只有一个,即:读取了本该没有的值或者地址。
 
那么如何解决呢?
 
第一件事,检查下你传入的参数是否合法;
第二件事,若malloc了一块内存,必须记得free;

第三件事,你是否赋值了已经溢出的值或地址。

 
举例说明:
 
  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. if( A[0]==255 && A[1]==255 && A[2]==255 && A[3]==255 )
  11. {
  12. pOrg[x] = 255;  pOrg[x+1] = 255;
  13. (pOrg+stride)[x] = 255; (pOrg+stride)[x+1] = 255;
  14. }
  15. else
  16. {
  17. pOrg[x] = 0;    pOrg[x+1] = 0;
  18. (pOrg+stride)[x] = 0;   (pOrg+stride)[x+1] = 0;
  19. }
  20. x += 1;
  21. }
  22. pOrg += 2*stride;
  23. }

此代码就会出现上图所示错误。那么如何解决呢?

 
  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. if( A[0]==255 && A[1]==255 && A[2]==255 && A[3]==255 )
  11. {
  12. pOrg[x] = 255;  pOrg[x+1] = 255;
  13. (pOrg+stride)[x] = 255; (pOrg+stride)[x+1] = 255;
  14. }
  15. else
  16. {
  17. pOrg[x] = 0;    pOrg[x+1] = 0;
  18. (pOrg+stride)[x] = 0;   (pOrg+stride)[x+1] = 0;
  19. }
  20. x += 1;
  21. }
  22. pOrg += 2*stride;
  23. }

很明显,错误的原因在于:赋值了已经溢出的值。

 
若以后遇到类似问题,可以逐步检查上述提出的“三件事情”即可。

Unhandled exception at 0x........ in XXXX.exe: 0xC0000005:错误的更多相关文章

  1. Solve Error: Unhandled exception at 0x00905a4d in xxx.exe: 0xC0000005: Access violation.

    在使用Visual Studio进行项目开发的时候,有时候会遇到下面这个错误: Unhandled exception at 0x00905a4d in xxx.exe: 0xC0000005: Ac ...

  2. NET环境下的未处理异常(unhandled exception)的解决方案

    NET环境下的未处理异常(unhandled exception )的解决方案 .Net 框架提供了非常强大的异常处理机制,同时对一些非托管代码很难控制的系统问题比如指针越界,内存泄漏等提供了很好的解 ...

  3. [转]让程序在崩溃时体面的退出之Unhandled Exception

    原文地址:http://blog.csdn.net/starlee/article/details/6613424 程序是由代码编译出来的,而代码是由人写的.人非圣贤,孰能无过.所以由人写的代码有缺陷 ...

  4. Unhandled Exception: System.BadImageFormatException: Could not load file or assembly (2008R2配置x64website)

    .NET Error Message: Unhandled Exception: System.BadImageFormatException: Could not load file or asse ...

  5. Unhandled Exception:System.DllNotFoundException: Unable to load DLL"**":找不到指定的模块

    在项目中使用C#代码调用C++ DLL时.常常会出现这个问题:在开发者自己的电脑上运行没有问题,但是部署到客户电脑上时会出现下面问题: Unhandled Exception:System.DllNo ...

  6. android Unhandled exception type ParseException提示报错

    Unhandled exception type ParseException 意思指:你有一个方法会抛出异常,但是你没有捕捉. 依提示添加一下即可解决:

  7. JAVA 新手问题: Request 编码编译出错,Unhandled exception type UnsupportedEncodingException

    新手: 编写如下代码 private void Exec(HttpServletRequest Req,HttpServletResponse Response) //throws ServletEx ...

  8. Quartz:ERROR threw an unhandled Exception

    详细的错误信息如下: -- ::] ERROR org.quartz.core.JobRunShell: - Job group1.job1 threw an unhandled Exception: ...

  9. Unhandled Exxception “Unhandled exception type IOException”?

    Unhandled Exxception  “Unhandled exception type IOException”? 在Android studio中,自动遇见这个异常报错,如果eclipse会 ...

随机推荐

  1. final finally finalize

    final  //如果不是final 的话,我可以在checkInt方法内部把i的值改变(有意或无意的,       //虽然不会改变实际调用处的值),特别是无意的,可能会引用一些难以发现的BUG   ...

  2. 《C++ Primer》学习笔记【第三部分 类设计者的工具】

    第13章 拷贝控制 使用default:=defult只能修饰默认构造函数或拷贝控制成员,显式地要去编译器生成合成的版本. 使用delete:=delete通知编译器不希望定义这些成员,禁止试图使用它 ...

  3. Oracle 修改文件所有者

        # chown -R gpadmin /usr/local/greenplum-db     # chgrp -R gpadmin /usr/local/greenplum-db

  4. PHP简单文件上传

    一个简单的PHP上传文件的例子: upload.html <html> <body> <form action="upload.php" method ...

  5. checkbox选中 和是否选中

    <input type="checkbox" <%--value="1"--%> id="checkboxOneInput" ...

  6. C语言局部变量和全局变量的区别。——Arvin

    局变量是使用相同的内存块在整个类中存储一个值. 全局变量的存在主要有以下一些原因:  1,使用全局变量会占用更多的内存(因为其生命期长),不过在计算机配置很高的今天,这个不成为什么问题,除非使用的是巨 ...

  7. R语言实战(三)基本图形与基本统计分析

    本文对应<R语言实战>第6章:基本图形:第7章:基本统计分析 =============================================================== ...

  8. eclipse遇到不会部署的情况

    1.先看下右下角有没有在进行的进程,例如validating  验证中.那就关闭验证的选项 2.看下problem栏有没有问题.会导致building不了.

  9. 我是如何反编译D-Link路由器固件程序并发现它的后门的

    OK,又是周末晚上,没有约会,只有一大瓶Shasta汽水和全是快节奏的音乐…那就研究一下程序吧. 一时兴起,我下载了D-link无线路由器(型号:DIR-100 revA)的固件程序 v1.13.使用 ...

  10. Windbg使用简明指南

    第一章 准备 1.1.    环境配置 _NT_DEBUGGER_EXTENSION_PATH=C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 _NT_SY ...