There is a lot of casting from char* to unsigned char* and vice-versa when dealing with binary data from files. This requires a reinterpret_cast, but since most of the code uses C-style casts, this has gone unnoticed. This mostly appears to be caused by inattentiveness, the casts should be where they are needed and not hidden away in strange places.
We should try to pick the type which will require us to use the fewest amount of casts. It cannot be avoided everywhere as it is not consistent in the libraries which is used. For example Qt uses char while libexif uses unsigned char. unsigned char appears to be the better choice, but it should be more clear when starting to look deeper into the code.
Checklist:
meta.h / libexif
ReaderPng / libpng
ReaderJpeg / libjpeg
colorManager.h / liblcms2
libpng is a bit tricky. png_byte is defined to be unsigned char in png_conf.h, but this could potentally change, as png_conf.h states:
The typedefs should be at least as large as the numbers suggest (a png_uint_32 must be at least 32 bits long), but they don't have to be exactly that size.
So someone could potentially change it to a larger type, and the cast would be wrong. We should have a static_assert to check that the sizes are the same.
There is a lot of casting from
char*
tounsigned char*
and vice-versa when dealing with binary data from files. This requires areinterpret_cast
, but since most of the code uses C-style casts, this has gone unnoticed. This mostly appears to be caused by inattentiveness, the casts should be where they are needed and not hidden away in strange places.We should try to pick the type which will require us to use the fewest amount of casts. It cannot be avoided everywhere as it is not consistent in the libraries which is used. For example Qt uses
char
while libexif usesunsigned char
.unsigned char
appears to be the better choice, but it should be more clear when starting to look deeper into the code.Checklist:
meta.h / libexiflibpng is a bit tricky.
png_byte
is defined to beunsigned char
inpng_conf.h
, but this could potentally change, aspng_conf.h
states:So someone could potentially change it to a larger type, and the cast would be wrong. We should have a
static_assert
to check that the sizes are the same.