Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix implicit 64 to 32 bit conversion warnings #3955

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/bmp.imageio/bmpoutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ BmpOutput::write_scanline(int y, int z, TypeDesc format, const void* data,

// Swap RGB pixels into BGR format
if (m_spec.nchannels >= 3)
for (int i = 0, iend = m_buf.size() - 2; i < iend;
for (size_t i = 0, iend = m_buf.size() - 2; i < iend;
i += m_spec.nchannels)
std::swap(m_buf[i], m_buf[i + 2]);

Expand Down Expand Up @@ -202,7 +202,7 @@ BmpOutput::create_and_write_file_header(void)
int64_t data_size = m_padded_scanline_size * m_spec.height;
int palettesize = (m_spec.nchannels == 1) ? 4 * 256 : 0;
int64_t file_size = data_size + BMP_HEADER_SIZE + WINDOWS_V3 + palettesize;
m_bmp_header.fsize = file_size;
m_bmp_header.fsize = (int32_t)file_size;
m_bmp_header.res1 = 0;
m_bmp_header.res2 = 0;
m_bmp_header.offset = BMP_HEADER_SIZE + WINDOWS_V3 + palettesize;
Expand Down
8 changes: 4 additions & 4 deletions src/cineon.imageio/libcineon/EndianSwap.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ inline char SwapBytes( char& value )


template <typename T>
void SwapBuffer(T *buf, unsigned int len)
void SwapBuffer(T *buf, size_t len)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what's going on here. The parameter was unsigned int, and the loop variable below is also unsigned int. Why change to size_t? And if the param is size_t, doesn't it just make a new potential problem or warning in the loop below that still is unsigned int?

Copy link
Contributor Author

@antond-weta antond-weta Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SwapBuffer gets called from EndianSwapImageBuffer, passing the length parameter. EndianSwapImageBuffer in turn is called from multiple places with size_t as the length parameter. Changing the param type seemed more logical to me. I have indeed overlooked the int in the loop.

{
for (unsigned int i = 0; i < len; i++)
for (size_t i = 0; i < len; i++)
SwapBytes(buf[i]);
}


template <DataSize SIZE>
void EndianSwapImageBuffer(void *data, int length)
void EndianSwapImageBuffer(void *data, size_t length)
{
switch (SIZE)
{
Expand All @@ -116,7 +116,7 @@ void EndianSwapImageBuffer(void *data, int length)
}


inline void EndianSwapImageBuffer(DataSize size, void *data, int length)
inline void EndianSwapImageBuffer(DataSize size, void *data, size_t length)
{
switch (size)
{
Expand Down
10 changes: 8 additions & 2 deletions src/cmake/compiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,15 @@ if (CMAKE_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_APPLECLANG)
# Don't warn about using unknown preprocessor symbols in `#if`
add_compile_options ("-Wno-expansion-to-defined")
endif ()
if (CMAKE_GENERATOR MATCHES "Xcode")
add_compile_options ("-Wno-shorten-64-to-32")
# if (CMAKE_GENERATOR MATCHES "Xcode")
# add_compile_options ("-Wno-shorten-64-to-32")
# endif ()

if (NOT WIN32)
add_compile_options ("-Wshorten-64-to-32")
add_compile_options ("-Wsign-compare")
endif ()

endif ()

if (CMAKE_COMPILER_IS_GNUCC AND NOT (CMAKE_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_APPLECLANG))
Expand Down
4 changes: 2 additions & 2 deletions src/dds.imageio/ddsinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,10 @@ DDSInput::internal_seek_subimage(int cubeface, int miplevel, unsigned int& w,
// we can easily calculate the offsets because both compressed and
// uncompressed images have predictable length
// calculate the offset; start with after the header
unsigned int ofs = sizeof(dds_header);
size_t ofs = sizeof(dds_header);
if (m_dds.fmt.fourCC == DDS_4CC_DX10)
ofs += sizeof(dds_header_dx10);
unsigned int len;
size_t len;
// this loop is used to iterate over cube map sides, or run once in the
// case of ordinary 2D or 3D images
for (int j = 0; j <= cubeface; j++) {
Expand Down
8 changes: 4 additions & 4 deletions src/dicom.imageio/dicominput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ DICOMInput::seek_subimage(int subimage, int miplevel)
errorf("Unable to open DICOM file %s", m_filename);
return false;
}
m_framecount = m_img->getFrameCount();
m_firstframe = m_img->getFirstFrame();
m_framecount = (int)m_img->getFrameCount();
m_firstframe = (int)m_img->getFirstFrame();
}

if (subimage >= m_firstframe + m_framecount) {
Expand Down Expand Up @@ -226,7 +226,7 @@ DICOMInput::seek_subimage(int subimage, int miplevel)
}
}

m_spec = ImageSpec(m_img->getWidth(), m_img->getHeight(), nchannels,
m_spec = ImageSpec((int)m_img->getWidth(), (int)m_img->getHeight(), nchannels,
format);

m_bitspersample = m_img->getDepth();
Expand Down Expand Up @@ -337,7 +337,7 @@ DICOMInput::read_native_scanline(int subimage, int miplevel, int y, int /*z*/,
memcpy(data, m_internal_data + y * size, size);

// Handle non-full bit depths
int bits = m_spec.format.size() * 8;
int bits = (int)m_spec.format.size() * 8;
if (bits != m_bitspersample) {
size_t n = m_spec.width * m_spec.nchannels;
if (m_spec.format == TypeDesc::UINT8) {
Expand Down
2 changes: 1 addition & 1 deletion src/dpx.imageio/dpxoutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ DPXOutput::prep_subimage(int s, bool allocate)
}

// calculate target bit depth
m_bitdepth = spec_s.format.size() * 8;
m_bitdepth = (int)spec_s.format.size() * 8;
if (spec_s.format == TypeDesc::UINT16) {
m_bitdepth = spec_s.get_int_attribute("oiio:BitsPerSample", 16);
if (m_bitdepth != 10 && m_bitdepth != 12 && m_bitdepth != 16) {
Expand Down
6 changes: 3 additions & 3 deletions src/dpx.imageio/libdpx/EndianSwap.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ inline char SwapBytes( char& value )


template <typename T>
void SwapBuffer(T *buf, unsigned int len)
void SwapBuffer(T *buf, size_t len)
{
for (unsigned int i = 0; i < len; i++)
SwapBytes(buf[i]);
}


template <DataSize SIZE>
void EndianSwapImageBuffer(void *data, int length)
void EndianSwapImageBuffer(void *data, size_t length)
{
switch (SIZE)
{
Expand All @@ -120,7 +120,7 @@ void EndianSwapImageBuffer(void *data, int length)
}


inline void EndianSwapImageBuffer(DataSize size, void *data, int length)
inline void EndianSwapImageBuffer(DataSize size, void *data, size_t length)
{
switch (size)
{
Expand Down
14 changes: 7 additions & 7 deletions src/dpx.imageio/libdpx/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ bool dpx::Writer::WriteHeader()

void dpx::Writer::SetUserData(const long size)
{
this->header.SetUserSize(size);
this->header.SetUserSize((U32)size);
}


Expand Down Expand Up @@ -185,8 +185,8 @@ void dpx::Writer::SetElement(const int num, const Descriptor desc, const U8 bitD
bool
dpx::Writer::WritePadData(const int alignment)
{
int imageoffset = ((this->fileLoc + alignment - 1)/alignment)*alignment;
int padsize = imageoffset - this->fileLoc;
long imageoffset = ((this->fileLoc + alignment - 1)/alignment)*alignment;
long padsize = imageoffset - this->fileLoc;
if (padsize > 0) {
std::vector<dpx::U8> pad (padsize, 0xff);
this->fileLoc += this->fd->Write (&pad[0], padsize);
Expand All @@ -213,7 +213,7 @@ bool dpx::Writer::WriteElement(const int element, void *data, const long count)
return false;

// update file ptr
this->header.SetDataOffset(element, this->fileLoc);
this->header.SetDataOffset(element, (U32)this->fileLoc);
this->fileLoc += count;

// write
Expand Down Expand Up @@ -253,8 +253,8 @@ bool dpx::Writer::WriteElement(const int element, void *data, const DataSize siz

// mark location in headers
if (element == 0)
this->header.SetImageOffset(this->fileLoc);
this->header.SetDataOffset(element, this->fileLoc);
this->header.SetImageOffset((U32)this->fileLoc);
this->header.SetDataOffset(element, (U32)this->fileLoc);

// reverse the order of the components
bool reverse = false;
Expand Down Expand Up @@ -426,7 +426,7 @@ bool dpx::Writer::WriteThrough(void *data, const U32 width, const U32 height, co
bool dpx::Writer::Finish()
{
// write the file size in the header
this->header.SetFileSize(this->fileLoc);
this->header.SetFileSize((U32)this->fileLoc);

// rewrite all of the offsets in the header
return this->header.WriteOffsetData(this->fd);
Expand Down
2 changes: 1 addition & 1 deletion src/fits.imageio/fits_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace fits_pvt {
// struct in which we store information about one subimage. This information
// allow us to set up pointer at the beginning of given subimage
struct Subimage {
int number;
size_t number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change here? Subimages in OIIO are ints and other formats store their equivalent as an int. Actually is this even used? I see one line that sets this value but nothing ever reads from it; maybe remove it entirely.

size_t offset;
};

Expand Down
4 changes: 2 additions & 2 deletions src/hdr.imageio/hdrinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class HdrInput final : public ImageInput {
bool read_native_scanline(int subimage, int miplevel, int y, int z,
void* data) override;
bool close() override;
int current_subimage(void) const override { return m_subimage; }
int current_subimage(void) const override { return (int)m_subimage; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unintentional change? m_subimage is already an int?

bool seek_subimage(int subimage, int miplevel) override;

private:
Expand Down Expand Up @@ -488,7 +488,7 @@ HdrInput::read_native_scanline(int subimage, int miplevel, int y, int /*z*/,
if (m_next_scanline != y) {
// For random access, use cached file offsets of scanlines. This avoids
// re-reading the same pixels many times over.
m_next_scanline = std::min((size_t)y, m_scanline_offsets.size() - 1);
m_next_scanline = std::min(y, (int)m_scanline_offsets.size() - 1);
ioseek(m_scanline_offsets[m_next_scanline]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/heif.imageio/heifoutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ HeifOutput::close()
exifblob.insert(exifblob.begin(), head.begin(), head.end());
try {
m_ctx->add_exif_metadata(m_ihandle, exifblob.data(),
exifblob.size());
(int)exifblob.size());
} catch (const heif::Error& err) {
#ifdef DEBUG
std::string e = err.get_message();
Expand Down
8 changes: 4 additions & 4 deletions src/ico.imageio/icooutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ ICOOutput::open(const std::string& name, const ImageSpec& userspec,
// need to move stuff around to make room for another subimage header
int subimage = ico.count++;
fseek(m_file, 0, SEEK_END);
int len = ftell(m_file);
long len = ftell(m_file);
unsigned char buf[512];
// append null data at the end of file so that we don't seek beyond eof
if (!fwrite(buf, sizeof(ico_subimage))) {
Expand All @@ -234,8 +234,8 @@ ICOOutput::open(const std::string& name, const ImageSpec& userspec,

// do the actual moving, 0.5kB per iteration
int skip = sizeof(ico_header) + sizeof(ico_subimage) * (subimage - 1);
for (int left = len - skip; left > 0; left -= sizeof(buf)) {
int amount = std::min(left, (int)sizeof(buf));
for (long left = len - skip; left > 0; left -= sizeof(buf)) {
long amount = std::min(left, (long)sizeof(buf));
/*std::cerr << "[ico] moving " << amount << " bytes (" << left
<< " vs " << sizeof (buf) << ")\n";*/
fseek(m_file, skip + left - amount, SEEK_SET);
Expand Down Expand Up @@ -284,7 +284,7 @@ ICOOutput::open(const std::string& name, const ImageSpec& userspec,
}

// offset at which we'll be writing new image data
m_offset = len + sizeof(ico_subimage);
m_offset = (int)(len + sizeof(ico_subimage));

// next part of code expects the file pointer to be where the new
// subimage header is to be written
Expand Down
10 changes: 5 additions & 5 deletions src/iff.imageio/iffinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ IffInput::read_header()
// tbmp position for later user in in
// read_native_tile

m_iff_header.tbmp_start = iotell();
m_iff_header.tbmp_start = (uint32_t)iotell();

// read first RGBA block to detect tile size.

Expand Down Expand Up @@ -537,7 +537,7 @@ IffInput::readimg()
uint8_t channels = m_iff_header.pixel_channels;

// set tile size
uint32_t tile_size = tw * th * channels * m_spec.channel_bytes()
size_t tile_size = tw * th * channels * m_spec.channel_bytes()
+ 8;

// test if compressed
Expand All @@ -562,7 +562,7 @@ IffInput::readimg()
// tile compress.
if (tile_compress) {
// map BGR(A) to RGB(A)
for (int c = (channels * m_spec.channel_bytes()) - 1;
for (int c = (int)(channels * m_spec.channel_bytes()) - 1;
c >= 0; --c) {
std::vector<uint8_t> in(tw * th);
uint8_t* in_p = &in[0];
Expand Down Expand Up @@ -644,7 +644,7 @@ IffInput::readimg()
}

// map BGR(A)BGR(A) to RRGGBB(AA)
for (int c = (channels * m_spec.channel_bytes()) - 1;
for (size_t c = (channels * m_spec.channel_bytes()) - 1;
c >= 0; --c) {
int mc = map[c];

Expand Down Expand Up @@ -724,7 +724,7 @@ IffInput::readimg()
// flip buffer to make read_native_tile easier,
// from tga.imageio:

int bytespp = m_spec.pixel_bytes();
size_t bytespp = m_spec.pixel_bytes();

std::vector<unsigned char> flip(m_spec.width * bytespp);
unsigned char *src, *dst, *tmp = &flip[0];
Expand Down
18 changes: 10 additions & 8 deletions src/iff.imageio/iffoutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ IffOutput::write_header(IffFileHeader& header)
write_meta_string("DATE", header.date);

// for4 position for later user in close
header.for4_start = iotell();
header.for4_start = (uint32_t)iotell();

// write 'FOR4' type, with 0 length to reserve it for now
if (!write_str("FOR4") || !write_int(0))
Expand Down Expand Up @@ -350,7 +350,7 @@ IffOutput::close(void)
// flip buffer to make write tile easier,
// from tga.imageio:

int bytespp = m_spec.pixel_bytes();
size_t bytespp = m_spec.pixel_bytes();

std::vector<unsigned char> flip(m_spec.width * bytespp);
unsigned char *src, *dst, *tmp = &flip[0];
Expand Down Expand Up @@ -388,7 +388,7 @@ IffOutput::close(void)
return false;

// length.
uint32_t length = tw * th * m_spec.pixel_bytes();
uint32_t length = tw * th * (uint32_t)m_spec.pixel_bytes();

// tile length.
uint32_t tile_length = length;
Expand All @@ -411,14 +411,15 @@ IffOutput::close(void)
// handle 8-bit data
if (m_spec.format == TypeDesc::UINT8) {
if (tile_compress) {
uint32_t index = 0, size = 0;
uint32_t index = 0;
size_t size = 0;
std::vector<uint8_t> tmp;

// set bytes.
tmp.resize(tile_length * 2);

// map: RGB(A) to BGRA
for (int c = (channels * m_spec.channel_bytes()) - 1;
for (long c = (channels * m_spec.channel_bytes()) - 1;
c >= 0; --c) {
std::vector<uint8_t> in(tw * th);
uint8_t* in_p = &in[0];
Expand Down Expand Up @@ -497,7 +498,8 @@ IffOutput::close(void)
// handle 16-bit data
else if (m_spec.format == TypeDesc::UINT16) {
if (tile_compress) {
uint32_t index = 0, size = 0;
uint32_t index = 0;
size_t size = 0;
std::vector<uint8_t> tmp;

// set bytes.
Expand Down Expand Up @@ -525,7 +527,7 @@ IffOutput::close(void)
}

// map: RRGGBB(AA) to BGR(A)BGR(A)
for (int c = (channels * m_spec.channel_bytes()) - 1;
for (long c = (channels * m_spec.channel_bytes()) - 1;
c >= 0; --c) {
int mc = map[c];

Expand Down Expand Up @@ -624,7 +626,7 @@ IffOutput::close(void)
}

// set sizes
uint32_t pos(iotell());
uint32_t pos((uint32_t)iotell());

uint32_t p0 = pos - 8;
uint32_t p1 = p0 - m_iff_header.for4_start;
Expand Down
4 changes: 2 additions & 2 deletions src/igrep/igrep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ grep_file(const std::string& filename, std::regex& re,
for (auto&& p : spec.extra_attribs) {
TypeDesc t = p.type();
if (t.elementtype() == TypeDesc::STRING) {
int n = t.numelements();
for (int i = 0; i < n; ++i) {
size_t n = t.numelements();
for (size_t i = 0; i < n; ++i) {
bool match = false;
try {
match = std::regex_search(((const char**)p.data())[i],
Expand Down
Loading
Loading