Skip to content

Commit

Permalink
fix: various internal fixes to address Sonar and other warnings (#4577)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
lgritz authored Dec 31, 2024
1 parent bff3377 commit fd411a6
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 26 deletions.
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ sonar.links.issue=https://github.com/AcademySoftwareFoundation/OpenImageIO/issue

# Source properties
sonar.sources=src
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
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
sonar.sourceEncoding=UTF-8

# C/C++ analyzer properties
Expand Down
11 changes: 5 additions & 6 deletions src/dpx.imageio/dpxoutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class DPXOutput final : public ImageOutput {

/// Helper function - set keycode values from int array
///
void set_keycode_values(int* array);
void set_keycode_values(cspan<int> array);
};


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

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

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


void
DPXOutput::set_keycode_values(int* array)
DPXOutput::set_keycode_values(cspan<int> array)
{
// Manufacturer code
{
Expand Down Expand Up @@ -760,8 +759,8 @@ DPXOutput::set_keycode_values(int* array)
}

// Format
int& perfsPerFrame = array[5];
int& perfsPerCount = array[6];
int perfsPerFrame = array[5];
int perfsPerCount = array[6];

if (perfsPerFrame == 15 && perfsPerCount == 120) {
Strutil::safe_strcpy(m_dpx.header.format, "8kimax",
Expand Down
10 changes: 5 additions & 5 deletions src/include/OpenImageIO/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ class OIIO_UTIL_API Benchmarker {
size_t m_trials = 10;
size_t m_work = 1;
std::string m_name;
std::vector<double> m_times; // times for each trial
double m_avg; // average time per iteration
double m_stddev; // standard deviation per iteration
double m_range; // range per iteration
double m_median; // median per-iteration time
std::vector<double> m_times; // times for each trial
double m_avg = 0.0; // average time per iteration
double m_stddev = 0.0; // standard deviation per iteration
double m_range = 0.0; // range per iteration
double m_median = 0.0; // median per-iteration time
int m_exclude_outliers = 1;
int m_verbose = 1;
int m_indent = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/libOpenImageIO/color_ocio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,9 +760,9 @@ ColorConfig::Impl::identify_builtin_equivalents()
const char*
ColorConfig::Impl::IdentifyBuiltinColorSpace(const char* name) const
{
#if OCIO_VERSION_HEX >= MAKE_OCIO_VERSION_HEX(2, 3, 0)
if (!config_ || disable_builtin_configs)
return nullptr;
#if OCIO_VERSION_HEX >= MAKE_OCIO_VERSION_HEX(2, 3, 0)
try {
return OCIO::Config::IdentifyBuiltinColorSpace(config_, builtinconfig_,
name);
Expand Down
7 changes: 1 addition & 6 deletions src/libutil/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1003,10 +1003,9 @@ Filesystem::scan_for_matching_filenames(const std::string& pattern,
// case 3: pattern has format, but no view
return scan_for_matching_filenames(pattern, frame_numbers, filenames);
}

return true;
}


bool
Filesystem::scan_for_matching_filenames(const std::string& pattern_,
std::vector<int>& numbers,
Expand Down Expand Up @@ -1285,10 +1284,6 @@ Filesystem::IOFile::pwrite(const void* buf, size_t size, int64_t offset)
// FIXME: the system pwrite returns ssize_t and is -1 on error.
return r < 0 ? size_t(0) : size_t(r);
#endif
offset += r;
if (m_pos > int64_t(m_size))
m_size = offset;
return r;
}

size_t
Expand Down
9 changes: 4 additions & 5 deletions src/libutil/sysutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,8 @@ Sysutil::put_in_background(int argc, char* argv[])
// Simplest case:
// daemon returns 0 if successful, thus return true if successful
return daemon(1, 1) == 0;
#endif

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

#ifdef _WIN32
#elif defined(_WIN32)
return true;
#endif

#else
// Otherwise, we don't know what to do
return false;
#endif
}


Expand Down
1 change: 1 addition & 0 deletions src/openexr.imageio/exrinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,7 @@ OpenEXRInput::read_native_scanlines(int subimage, int miplevel, int ybegin,
m_input_rgba->readPixels(ybegin, yend - 1);

// FIXME There is probably some optimized code for this somewhere.
OIIO_DASSERT(chbegin >= 0 && chend > chbegin);
for (int c = chbegin; c < chend; ++c) {
size_t chanbytes = m_spec.channelformat(c).size();
half* src = &pixels[0][0].r + c;
Expand Down
4 changes: 2 additions & 2 deletions src/openexr.imageio/exroutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1066,10 +1066,10 @@ OpenEXROutput::put_parameter(const std::string& name, TypeDesc type,
Imf::FloatAttribute((float)*(half*)data));
return true;
}
if (type == TypeString && *(const char**)data) {
if (type == TypeString && !((const ustring*)data)->empty()) {
header.insert(xname.c_str(),
Imf::StringAttribute(
*(const char**)data)); //NOSONAR
((const ustring*)data)->c_str()));
return true;
}
if (type == TypeDesc::DOUBLE) {
Expand Down

0 comments on commit fd411a6

Please sign in to comment.