HReddy118194 (Community Member) asked a question.

I am getting an integer overflow error for the following code. Please help me to fix this error.

Errors are on lines:

  • size_t pixelCount = width * height;
  • size_t componentCount = pixelCount << 2;
  • size_t bytesPerRow = width << 2;

where size_t is unsigned long long.

 

 

PLRGBImageRef _Nullable CreateDocProcessingEngine(uint8_t *_Nonnull ioBytes,

            int inWidth, int inHeight)

try

{

    size_t width = static_cast<size_t>(inWidth);

    size_t height = static_cast<size_t>(inHeight);

    size_t pixelCount = width * height;

    if (0 == (size_t(ioBytes) % alignof(uint32_t)))

    {

        uint32_t *pixels = reinterpret_cast<uint32_t *>(ioBytes);

        for (size_t i = 0; i < pixelCount; i++)

        {

            if (0 == pixels[i])

            {

                pixels[i] = 0xFFFFFFFF;

            }

        }

    }

    else

    {

        size_t componentCount = pixelCount << 2;

        uint32_t blackPixel = 0;

        for (size_t i = 0; i < componentCount; i += 4)

        {

            if (0 == memcmp(&ioBytes[i], &blackPixel, 4))

            {

                memset(&ioBytes[i], 0xFF, 4);

            }

        }

    }

    size_t bytesPerRow = width << 2;

    unique_ptr<RGBXImage> rgbaImage(new RGBXImage(ioBytes,

                {height, width, bytesPerRow}, 0, 0));

    RGBImage *rgbImage = rgbaImage->ToRGB();

    return rgbImage;

}


Topics (5)

No articles found
Loading

Ask the Community

Get answers, share a use case, discuss your favorite features, or get input from the community.