To fix this, all the fields of Image should become private, which would be a breaking change.
The Image::width and Image::height methods for immutable reading already exist as a replacement, along with Image::get_image_data.
Unsafe methods for changing the width and height could be added too if there is a legitimate use case.
The following safe code causes undefined behaviour by reading out of bounds:
To fix this, all the fields of
Image
should become private, which would be a breaking change. TheImage::width
andImage::height
methods for immutable reading already exist as a replacement, along withImage::get_image_data
.Unsafe methods for changing the width and height could be added too if there is a legitimate use case.