【问题标题】:Getting a segmentation fault in c在c中获得分段错误
【发布时间】:2015-01-12 11:50:06
【问题描述】:

所以这个功能就是把图像中的区域变成某种颜色。但是当我运行这段代码时,它给了我一个分段错误。我不知道为什么它一直给我这个错误。有人可以帮助我吗?这是我的代码:

void region_set( uint8_t array[], 
         unsigned int cols, 
         unsigned int rows,
         unsigned int left,
         unsigned int top,
         unsigned int right,
         unsigned int bottom,
         uint8_t color )
{   
    for (int x = 0; x < ((right-left)*(top-bottom)); x++)
    {
        array[x] = color;
    }
}

【问题讨论】:

  • 你传入了什么值,数组是如何初始化的?
  • 我传入(array, 256, 256, 0, 50, 50, 0, 255)
  • 一个很好的猜测是您的数组大小对于您的输入参数来说太小了。
  • 另外,这段代码不会做你想做的事:你没有使用 cols 或 rows 参数,这是了解你需要访问 array[] 多远才能获取的必要参数右栏。
  • 所有警告和调试信息gcc -Wall -Wextra -g)编译你的所有程序,然后使用调试器(@ 987654324@) - 和valgrind(如果有)。错误可能在调用者中。

标签: c colors segmentation-fault


【解决方案1】:

好像"array[]"的大小小于"((right-left)*(top-bottom))",

【讨论】:

    猜你喜欢
    • 2012-10-10
    • 1970-01-01
    • 2021-12-02
    • 1970-01-01
    • 1970-01-01
    • 2011-12-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多