Skip to content

Commit fd411a6

Browse files
authored
fix: various internal fixes to address Sonar and other warnings (#4577)
Chipping away at minor warnings and areas identified by static analysis as potentially problematic or hard to analyze. * benchmark.h: suppress warnings about uninitialized Benchmarker members. * dpxoutput.cpp: change some raw pointers to spans * dead code removal (color_ocio.cpp, filesystem.cpp, sysutil.cpp) * exclude build-scripts from static analysis * some misc warning suppression Signed-off-by: Larry Gritz <[email protected]>
1 parent bff3377 commit fd411a6

File tree

8 files changed

+20
-26
lines changed

8 files changed

+20
-26
lines changed

sonar-project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ sonar.links.issue=https://github.com/AcademySoftwareFoundation/OpenImageIO/issue
1717

1818
# Source properties
1919
sonar.sources=src
20-
sonar.exclusions=src/doc/**,src/include/OpenImageIO/detail/pugixml/**,src/libutil/stb_sprintf.h,src/libutil/xxhash.cpp,src/include/OpenImageIO/detail/farmhash.h,src/libutil/farmhash.cpp
20+
sonar.exclusions=src/doc/**,src/build-scripts/**,src/include/OpenImageIO/detail/pugixml/**,src/libutil/stb_sprintf.h,src/libutil/xxhash.cpp,src/include/OpenImageIO/detail/farmhash.h,src/libutil/farmhash.cpp
2121
sonar.sourceEncoding=UTF-8
2222

2323
# C/C++ analyzer properties

src/dpx.imageio/dpxoutput.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class DPXOutput final : public ImageOutput {
104104

105105
/// Helper function - set keycode values from int array
106106
///
107-
void set_keycode_values(int* array);
107+
void set_keycode_values(cspan<int> array);
108108
};
109109

110110

@@ -370,8 +370,7 @@ DPXOutput::open(const std::string& name, const ImageSpec& userspec,
370370

371371
ParamValue* kc = spec0.find_attribute("smpte:KeyCode", TypeKeyCode, false);
372372
if (kc) {
373-
int* array = (int*)kc->data();
374-
set_keycode_values(array);
373+
set_keycode_values(cspan<int>((int*)kc->data(), 7));
375374

376375
// See if there is an overloaded dpx:Format
377376
std::string format = spec0.get_string_attribute("dpx:Format", "");
@@ -727,7 +726,7 @@ DPXOutput::get_image_descriptor()
727726

728727

729728
void
730-
DPXOutput::set_keycode_values(int* array)
729+
DPXOutput::set_keycode_values(cspan<int> array)
731730
{
732731
// Manufacturer code
733732
{
@@ -760,8 +759,8 @@ DPXOutput::set_keycode_values(int* array)
760759
}
761760

762761
// Format
763-
int& perfsPerFrame = array[5];
764-
int& perfsPerCount = array[6];
762+
int perfsPerFrame = array[5];
763+
int perfsPerCount = array[6];
765764

766765
if (perfsPerFrame == 15 && perfsPerCount == 120) {
767766
Strutil::safe_strcpy(m_dpx.header.format, "8kimax",

src/include/OpenImageIO/benchmark.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,11 @@ class OIIO_UTIL_API Benchmarker {
243243
size_t m_trials = 10;
244244
size_t m_work = 1;
245245
std::string m_name;
246-
std::vector<double> m_times; // times for each trial
247-
double m_avg; // average time per iteration
248-
double m_stddev; // standard deviation per iteration
249-
double m_range; // range per iteration
250-
double m_median; // median per-iteration time
246+
std::vector<double> m_times; // times for each trial
247+
double m_avg = 0.0; // average time per iteration
248+
double m_stddev = 0.0; // standard deviation per iteration
249+
double m_range = 0.0; // range per iteration
250+
double m_median = 0.0; // median per-iteration time
251251
int m_exclude_outliers = 1;
252252
int m_verbose = 1;
253253
int m_indent = 0;

src/libOpenImageIO/color_ocio.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,9 +760,9 @@ ColorConfig::Impl::identify_builtin_equivalents()
760760
const char*
761761
ColorConfig::Impl::IdentifyBuiltinColorSpace(const char* name) const
762762
{
763+
#if OCIO_VERSION_HEX >= MAKE_OCIO_VERSION_HEX(2, 3, 0)
763764
if (!config_ || disable_builtin_configs)
764765
return nullptr;
765-
#if OCIO_VERSION_HEX >= MAKE_OCIO_VERSION_HEX(2, 3, 0)
766766
try {
767767
return OCIO::Config::IdentifyBuiltinColorSpace(config_, builtinconfig_,
768768
name);

src/libutil/filesystem.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,10 +1003,9 @@ Filesystem::scan_for_matching_filenames(const std::string& pattern,
10031003
// case 3: pattern has format, but no view
10041004
return scan_for_matching_filenames(pattern, frame_numbers, filenames);
10051005
}
1006-
1007-
return true;
10081006
}
10091007

1008+
10101009
bool
10111010
Filesystem::scan_for_matching_filenames(const std::string& pattern_,
10121011
std::vector<int>& numbers,
@@ -1285,10 +1284,6 @@ Filesystem::IOFile::pwrite(const void* buf, size_t size, int64_t offset)
12851284
// FIXME: the system pwrite returns ssize_t and is -1 on error.
12861285
return r < 0 ? size_t(0) : size_t(r);
12871286
#endif
1288-
offset += r;
1289-
if (m_pos > int64_t(m_size))
1290-
m_size = offset;
1291-
return r;
12921287
}
12931288

12941289
size_t

src/libutil/sysutil.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,8 @@ Sysutil::put_in_background(int argc, char* argv[])
552552
// Simplest case:
553553
// daemon returns 0 if successful, thus return true if successful
554554
return daemon(1, 1) == 0;
555-
#endif
556555

557-
#if defined(__APPLE__) && TARGET_OS_OSX
556+
#elif defined(__APPLE__) && TARGET_OS_OSX
558557
std::string newcmd = std::string(argv[0]) + " -F";
559558
for (int i = 1; i < argc; ++i) {
560559
newcmd += " \"";
@@ -565,14 +564,14 @@ Sysutil::put_in_background(int argc, char* argv[])
565564
if (system(newcmd.c_str()) != -1)
566565
exit(0);
567566
return true;
568-
#endif
569567

570-
#ifdef _WIN32
568+
#elif defined(_WIN32)
571569
return true;
572-
#endif
573570

571+
#else
574572
// Otherwise, we don't know what to do
575573
return false;
574+
#endif
576575
}
577576

578577

src/openexr.imageio/exrinput.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,7 @@ OpenEXRInput::read_native_scanlines(int subimage, int miplevel, int ybegin,
12091209
m_input_rgba->readPixels(ybegin, yend - 1);
12101210

12111211
// FIXME There is probably some optimized code for this somewhere.
1212+
OIIO_DASSERT(chbegin >= 0 && chend > chbegin);
12121213
for (int c = chbegin; c < chend; ++c) {
12131214
size_t chanbytes = m_spec.channelformat(c).size();
12141215
half* src = &pixels[0][0].r + c;

src/openexr.imageio/exroutput.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,10 +1066,10 @@ OpenEXROutput::put_parameter(const std::string& name, TypeDesc type,
10661066
Imf::FloatAttribute((float)*(half*)data));
10671067
return true;
10681068
}
1069-
if (type == TypeString && *(const char**)data) {
1069+
if (type == TypeString && !((const ustring*)data)->empty()) {
10701070
header.insert(xname.c_str(),
10711071
Imf::StringAttribute(
1072-
*(const char**)data)); //NOSONAR
1072+
((const ustring*)data)->c_str()));
10731073
return true;
10741074
}
10751075
if (type == TypeDesc::DOUBLE) {

0 commit comments

Comments
 (0)