error: Pointer addition with NULL pointer. [nullPointerArithmetic]

这个错误表明正在尝试对一个NULL指针进行指针相加操作。

size_t CompoundFile::WriteData(const char *data, size_t size, int startIndex, bool isBig)    {
    if (isBig) {
        if (size == 0 && startIndex == -2)
            return startIndex;

        // Get present indices
        vector<size_t> indices;
        GetBlockIndices(startIndex, indices, true);
        size_t maxPresentBlocks = indices.size();

        // Write blocks into available space
        size_t remainingFullBlocks = size / header_.bigBlockSize_;
        size_t curIndex = 0;
        if (maxPresentBlocks != 0)            {
            for (; remainingFullBlocks && curIndex < maxPresentBlocks;
                 --remainingFullBlocks, ++curIndex)                {
                file_.Write(indices[curIndex] + 1, data + curIndex * header_.bigBlockSize_);
            }
        }
    }
}

问题出现在file_.Write这行代码,需对data进行是否为空的判断,修改如下:

size_t CompoundFile::WriteData(const char *data, size_t size, int startIndex, bool isBig)    {
    if (isBig) {
        if (size == 0 && startIndex == -2)
            return startIndex;

        // Get present indices
        vector<size_t> indices;
        GetBlockIndices(startIndex, indices, true);
        size_t maxPresentBlocks = indices.size();

        // Write blocks into available space
        size_t remainingFullBlocks = size / header_.bigBlockSize_;
        size_t curIndex = 0;
        if (maxPresentBlocks != 0)            {
            for (; remainingFullBlocks && curIndex < maxPresentBlocks;
                 --remainingFullBlocks, ++curIndex)                {
                     if (data)
                          file_.Write(indices[curIndex] + 1, data + curIndex * header_.bigBlockSize_);

            }
        }
    }
}

再次编译,报错消失。

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-19 18:28:06       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-19 18:28:06       71 阅读
  3. 在Django里面运行非项目文件

    2024-07-19 18:28:06       58 阅读
  4. Python语言-面向对象

    2024-07-19 18:28:06       69 阅读

热门阅读

  1. 学术资源网站

    2024-07-19 18:28:06       24 阅读
  2. MySQL 删除重复记录

    2024-07-19 18:28:06       18 阅读
  3. go exporter开发 第一篇

    2024-07-19 18:28:06       17 阅读
  4. ubuntu23安装tensorRT步骤记录

    2024-07-19 18:28:06       18 阅读
  5. Unable to connect to Redis] with root cause

    2024-07-19 18:28:06       18 阅读
  6. redis时间环结构-时序特征

    2024-07-19 18:28:06       19 阅读