Skip to content

Commit 6b2f2e8

Browse files
committed
Fix compiler warnings
* static_cast for signed/unsigned integer comparisons * remove unused variables * fix order of member initialization * use override instead of virtual * printf %d -> %ld * clang pragmas Signed-off-by: Cary Phillips <[email protected]>
1 parent 637b071 commit 6b2f2e8

File tree

9 files changed

+47
-46
lines changed

9 files changed

+47
-46
lines changed

src/bin/exrmetrics/exrmetrics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ exrmetrics (
10011001

10021002
bool compressionSet = false;
10031003

1004-
for (int p = 0; p < outHeaders.size(); ++p)
1004+
for (size_t p = 0; p < outHeaders.size(); ++p)
10051005
{
10061006
if (compression < NUM_COMPRESSION_METHODS)
10071007
{

src/lib/OpenEXR/ImfBytesAttribute.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ BytesAttribute::BytesAttribute (
2828
size_t size,
2929
const void* data,
3030
const std::string& typeHint)
31-
: _data (size), typeHint (typeHint)
31+
: typeHint (typeHint), _data (size)
3232
{
3333
if (size > 0 && ! data)
3434
{
@@ -41,7 +41,7 @@ BytesAttribute::BytesAttribute (
4141
}
4242

4343
BytesAttribute::BytesAttribute (const BytesAttribute& other)
44-
: _data (other._data.size ()), typeHint (other.typeHint)
44+
: typeHint (other.typeHint), _data (other._data.size ())
4545
{
4646
memcpy (
4747
(unsigned char*) _data,
@@ -115,7 +115,7 @@ BytesAttribute::readValueFrom (
115115
unsigned int hintLength = 0;
116116
Xdr::read<StreamIO> (is, hintLength);
117117

118-
if (size < sizeof(hintLength) + hintLength)
118+
if (size < static_cast<int>(sizeof(hintLength) + hintLength))
119119
THROW (IEX_NAMESPACE::InputExc,
120120
"Invalid bytes attribute type string length: " << hintLength);
121121

src/lib/OpenEXR/ImfBytesAttribute.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,19 @@ class IMF_EXPORT_TYPE BytesAttribute : public Attribute
6060
// Make a copy of this attribute
6161
//------------------------------
6262

63-
IMF_EXPORT virtual Attribute* copy () const;
63+
IMF_EXPORT Attribute* copy () const override;
6464

6565
//----------------
6666
// I/O and copying
6767
//----------------
6868

69-
IMF_EXPORT virtual void writeValueTo (
70-
OPENEXR_IMF_INTERNAL_NAMESPACE::OStream& os, int version) const;
69+
IMF_EXPORT void writeValueTo (
70+
OPENEXR_IMF_INTERNAL_NAMESPACE::OStream& os, int version) const override;
7171

72-
IMF_EXPORT virtual void readValueFrom (
73-
OPENEXR_IMF_INTERNAL_NAMESPACE::IStream& is, int size, int version);
72+
IMF_EXPORT void readValueFrom (
73+
OPENEXR_IMF_INTERNAL_NAMESPACE::IStream& is, int size, int version) override;
7474

75-
IMF_EXPORT virtual void copyValueFrom (const Attribute& other);
75+
IMF_EXPORT void copyValueFrom (const Attribute& other) override;
7676

7777
size_t size () const { return _data.size (); }
7878
const Array<unsigned char>& data () const { return _data; }

src/lib/OpenEXRCore/internal_ht.cpp

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ ht_undo_impl (
174174
size_t header_sz;
175175
header_sz = read_header (
176176
(uint8_t*) compressed_data, comp_buf_size, cs_to_file_ch);
177-
if (decode->channel_count != cs_to_file_ch.size ())
177+
if (static_cast<std::size_t>(decode->channel_count) != cs_to_file_ch.size ())
178178
throw std::runtime_error ("Unexpected number of channels");
179179

180180
for (int cs_i = 0; cs_i < decode->channel_count; cs_i++)
@@ -199,16 +199,13 @@ ht_undo_impl (
199199
cs.read_headers (&infile);
200200

201201
ojph::param_siz siz = cs.access_siz ();
202-
ojph::param_nlt nlt = cs.access_nlt ();
203202

204-
ojph::ui32 image_width =
205-
siz.get_image_extent ().x - siz.get_image_offset ().x;
206203
ojph::ui32 image_height =
207204
siz.get_image_extent ().y - siz.get_image_offset ().y;
208205

209206
int bpl = 0;
210207
bool is_planar = false;
211-
for (ojph::ui32 c = 0; c < decode->channel_count; c++)
208+
for (ojph::ui32 c = 0; c < static_cast<ojph::ui32>(decode->channel_count); c++)
212209
{
213210
bpl +=
214211
decode->channels[c].bytes_per_element * decode->channels[c].width;
@@ -218,7 +215,7 @@ ht_undo_impl (
218215
}
219216
cs.set_planar (is_planar);
220217

221-
assert (decode->chunk.width == image_width);
218+
assert (decode->chunk.width == siz.get_image_extent ().x - siz.get_image_offset ().x);
222219
assert (decode->chunk.height == image_height);
223220
assert (decode->channel_count == siz.get_num_components ());
224221

@@ -230,7 +227,7 @@ ht_undo_impl (
230227
ojph::line_buf* cur_line;
231228
if (cs.is_planar ())
232229
{
233-
for (uint32_t c = 0; c < decode->channel_count; c++)
230+
for (uint32_t c = 0; c < static_cast<uint32_t>(decode->channel_count); c++)
234231
{
235232
int file_c = cs_to_file_ch[c].file_index;
236233
assert (
@@ -245,12 +242,12 @@ ht_undo_impl (
245242
y < image_height + decode->chunk.start_y;
246243
y++)
247244
{
248-
for (ojph::ui32 line_c = 0; line_c < decode->channel_count;
245+
for (ojph::ui32 line_c = 0; line_c < static_cast<ojph::ui32>(decode->channel_count);
249246
line_c++)
250247
{
251248
if (y % decode->channels[line_c].y_samples != 0) continue;
252249

253-
if (line_c == file_c)
250+
if (line_c == static_cast<ojph::ui32>(file_c))
254251
{
255252
cur_line = cs.pull (next_comp);
256253
assert (next_comp == c);
@@ -260,7 +257,7 @@ ht_undo_impl (
260257
{
261258
int16_t* channel_pixels = (int16_t*) line_pixels;
262259
for (uint32_t p = 0;
263-
p < decode->channels[file_c].width;
260+
p < static_cast<uint32_t>(decode->channels[file_c].width);
264261
p++)
265262
{
266263
*channel_pixels++ = cur_line->i32[p];
@@ -270,7 +267,7 @@ ht_undo_impl (
270267
{
271268
int32_t* channel_pixels = (int32_t*) line_pixels;
272269
for (uint32_t p = 0;
273-
p < decode->channels[file_c].width;
270+
p < static_cast<uint32_t>(decode->channels[file_c].width);
274271
p++)
275272
{
276273
*channel_pixels++ = cur_line->i32[p];
@@ -292,7 +289,7 @@ ht_undo_impl (
292289

293290
for (uint32_t y = 0; y < image_height; ++y)
294291
{
295-
for (uint32_t c = 0; c < decode->channel_count; c++)
292+
for (uint32_t c = 0; c < static_cast<uint32_t>(decode->channel_count); c++)
296293
{
297294
int file_c = cs_to_file_ch[c].file_index;
298295
cur_line = cs.pull (next_comp);
@@ -301,7 +298,7 @@ ht_undo_impl (
301298
{
302299
int16_t* channel_pixels =
303300
(int16_t*) (line_pixels + cs_to_file_ch[c].raster_line_offset);
304-
for (uint32_t p = 0; p < decode->channels[file_c].width;
301+
for (uint32_t p = 0; p < static_cast<uint32_t>(decode->channels[file_c].width);
305302
p++)
306303
{
307304
*channel_pixels++ = cur_line->i32[p];
@@ -311,7 +308,7 @@ ht_undo_impl (
311308
{
312309
int32_t* channel_pixels =
313310
(int32_t*) (line_pixels + cs_to_file_ch[c].raster_line_offset);
314-
for (uint32_t p = 0; p < decode->channels[file_c].width;
311+
for (uint32_t p = 0; p < static_cast<uint32_t>(decode->channels[file_c].width);
315312
p++)
316313
{
317314
*channel_pixels++ = cur_line->i32[p];
@@ -371,7 +368,7 @@ ht_apply_impl (exr_encode_pipeline_t* encode)
371368
bool isPlanar = false;
372369
siz.set_num_components (encode->channel_count);
373370
int bpl = 0;
374-
for (ojph::ui32 c = 0; c < encode->channel_count; c++)
371+
for (ojph::ui32 c = 0; c < static_cast<ojph::ui32>(encode->channel_count); c++)
375372
{
376373
int file_c = cs_to_file_ch[c].file_index;
377374
if (encode->channels[file_c].data_type != EXR_PIXEL_UINT)
@@ -425,7 +422,7 @@ ht_apply_impl (exr_encode_pipeline_t* encode)
425422

426423
if (cs.is_planar ())
427424
{
428-
for (ojph::ui32 c = 0; c < encode->channel_count; c++)
425+
for (ojph::ui32 c = 0; c < static_cast<ojph::ui32>(encode->channel_count); c++)
429426
{
430427
if (encode->channels[c].height == 0) continue;
431428

@@ -437,20 +434,20 @@ ht_apply_impl (exr_encode_pipeline_t* encode)
437434
y < image_height + encode->chunk.start_y;
438435
y++)
439436
{
440-
for (ojph::ui32 line_c = 0; line_c < encode->channel_count;
437+
for (ojph::ui32 line_c = 0; line_c < static_cast<ojph::ui32>(encode->channel_count);
441438
line_c++)
442439
{
443440

444441
if (y % encode->channels[line_c].y_samples != 0) continue;
445442

446-
if (line_c == file_c)
443+
if (line_c == static_cast<ojph::ui32>(file_c))
447444
{
448445
if (encode->channels[file_c].data_type ==
449446
EXR_PIXEL_HALF)
450447
{
451448
int16_t* channel_pixels = (int16_t*) (line_pixels);
452449
for (uint32_t p = 0;
453-
p < encode->channels[file_c].width;
450+
p < static_cast<ojph::ui32>(encode->channels[file_c].width);
454451
p++)
455452
{
456453
cur_line->i32[p] = *channel_pixels++;
@@ -460,7 +457,7 @@ ht_apply_impl (exr_encode_pipeline_t* encode)
460457
{
461458
int32_t* channel_pixels = (int32_t*) (line_pixels);
462459
for (uint32_t p = 0;
463-
p < encode->channels[file_c].width;
460+
p < static_cast<ojph::ui32>(encode->channels[file_c].width);
464461
p++)
465462
{
466463
cur_line->i32[p] = *channel_pixels++;
@@ -486,15 +483,15 @@ ht_apply_impl (exr_encode_pipeline_t* encode)
486483

487484
for (int y = 0; y < image_height; y++)
488485
{
489-
for (ojph::ui32 c = 0; c < encode->channel_count; c++)
486+
for (ojph::ui32 c = 0; c < static_cast<ojph::ui32>(encode->channel_count); c++)
490487
{
491488
int file_c = cs_to_file_ch[c].file_index;
492489

493490
if (encode->channels[file_c].data_type == EXR_PIXEL_HALF)
494491
{
495492
int16_t* channel_pixels =
496493
(int16_t*) (line_pixels + cs_to_file_ch[c].raster_line_offset);
497-
for (uint32_t p = 0; p < encode->channels[file_c].width;
494+
for (uint32_t p = 0; p < static_cast<uint32_t>(encode->channels[file_c].width);
498495
p++)
499496
{
500497
cur_line->i32[p] = *channel_pixels++;
@@ -504,7 +501,7 @@ ht_apply_impl (exr_encode_pipeline_t* encode)
504501
{
505502
int32_t* channel_pixels =
506503
(int32_t*) (line_pixels + cs_to_file_ch[c].raster_line_offset);
507-
for (uint32_t p = 0; p < encode->channels[file_c].width;
504+
for (uint32_t p = 0; p < static_cast<uint32_t>(encode->channels[file_c].width);
508505
p++)
509506
{
510507
cur_line->i32[p] = *channel_pixels++;

src/lib/OpenEXRCore/internal_ht_common.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
#include <cctype>
1313
#include <stdexcept>
1414

15-
const std::string RED_CH_FULLNAME = "red";
16-
const std::string GREEN_CH_FULLNAME = "green";
17-
const std::string BLUE_CH_FULLNAME = "blue";
18-
1915
struct RGBChannelParams
2016
{
2117
const char* r_suffix;
@@ -63,7 +59,7 @@ make_channel_map (
6359

6460
cs_to_file_ch.resize (channel_count);
6561

66-
for (size_t i = 0; i < channel_count; i++)
62+
for (size_t i = 0; i < static_cast<size_t>(channel_count); i++)
6763
{
6864
const char* channel_name = channels[i].channel_name;
6965
const char* suffix = strrchr (channel_name, '.');
@@ -147,14 +143,14 @@ make_channel_map (
147143

148144
int avail_cs_i = 3;
149145
int offset = 0;
150-
for (size_t file_i = 0; file_i < channel_count; file_i++)
146+
for (size_t file_i = 0; file_i < static_cast<size_t>(channel_count); file_i++)
151147
{
152148
int cs_i;
153-
if (file_i == r_index) {
149+
if (static_cast<int>(file_i) == r_index) {
154150
cs_i = 0;
155-
} else if (file_i == g_index) {
151+
} else if (static_cast<int>(file_i) == g_index) {
156152
cs_i = 1;
157-
} else if (file_i == b_index) {
153+
} else if (static_cast<int>(file_i) == b_index) {
158154
cs_i = 2;
159155
} else {
160156
cs_i = avail_cs_i++;
@@ -168,7 +164,7 @@ make_channel_map (
168164
else
169165
{
170166
int offset = 0;
171-
for (size_t file_i = 0; file_i < channel_count; file_i++)
167+
for (size_t file_i = 0; file_i < static_cast<size_t>(channel_count); file_i++)
172168
{
173169
cs_to_file_ch[file_i].file_index = file_i;
174170
cs_to_file_ch[file_i].raster_line_offset = offset;

src/lib/OpenEXRCore/internal_huf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,7 @@ fasthuf_decode (
17221722
// 8 bits of data in the buffer
17231723
//
17241724

1725-
if (symbol == rleSym)
1725+
if (symbol == (int) rleSym)
17261726
{
17271727
uint32_t rleCount;
17281728

src/lib/OpenEXRCore/parse_header.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ extract_attr_bytes(
773773
return ctxt->print_error (
774774
ctxt,
775775
EXR_ERR_ATTR_SIZE_MISMATCH,
776-
"Attribute '%s': Invalid size %d (exp '%s' size >= %d)",
776+
"Attribute '%s': Invalid size %d (exp '%s' size >= %ld)",
777777
aname,
778778
attrsz,
779779
tname,

src/lib/OpenEXRCore/string.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ exr_attr_string_create_with_length (
125125
#ifdef _MSC_VER
126126
# pragma warning(push)
127127
# pragma warning(disable : 4996)
128+
#elif defined(__clang__)
129+
// clang: do nothing
128130
#elif defined(__GNUC__)
129131
# pragma GCC diagnostic push
130132
# pragma GCC diagnostic ignored "-Wstringop-truncation"
@@ -135,6 +137,8 @@ exr_attr_string_create_with_length (
135137
memset (outs, 0, (size_t) len);
136138
#ifdef _MSC_VER
137139
# pragma warning(pop)
140+
#elif defined(__clang__)
141+
// clang: do nothing
138142
#elif defined(__GNUC__)
139143
# pragma GCC diagnostic pop
140144
#endif
@@ -199,6 +203,8 @@ exr_attr_string_set_with_length (
199203
#ifdef _MSC_VER
200204
# pragma warning(push)
201205
# pragma warning(disable : 4996)
206+
#elif defined(__clang__)
207+
// clang: do nothing
202208
#elif defined(__GNUC__)
203209
# pragma GCC diagnostic push
204210
# pragma GCC diagnostic ignored "-Wstringop-truncation"
@@ -209,6 +215,8 @@ exr_attr_string_set_with_length (
209215
memset (sstr, 0, (size_t) len);
210216
#ifdef _MSC_VER
211217
# pragma warning(pop)
218+
#elif defined(__clang__)
219+
// clang: do nothing
212220
#elif defined(__GNUC__)
213221
# pragma GCC diagnostic pop
214222
#endif

src/test/OpenEXRCoreTest/compression.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,7 @@ testHTChannelMap (const std::string& tempdir)
17221722
};
17231723
int test_count = sizeof(tests) / sizeof(ht_channel_map_tests);
17241724

1725-
for (size_t i = 0; i < test_count; i++)
1725+
for (size_t i = 0; i < static_cast<size_t>(test_count); i++)
17261726
{
17271727
EXRCORE_TEST (
17281728
make_channel_map (

0 commit comments

Comments
 (0)