Skip to content

Commit 86d40a2

Browse files
lgritz1div0
authored andcommitted
Fixes to reduce problems identified by static analysis (AcademySoftwareFoundation#4113)
* pngoutput.cpp: Catch possible exceptions. * printinfo.cpp: assertions to assure we don't dereference a null pointer. * testtex.cpp: make sure allocated chunk is initialized * WriterInternal.h: Catch condition that could lead to buffer underflow. * imagebufalgo_mad.cpp: Simplify pointless clause. The prior test was redundant. Since a few lines above, if B was an image but A was not, we swapped to ensure that A was always an image. So here, we can just test A to know for sure that at least one of them is an image. That makes the test here simpler, but it also makes it more clear to static analysis that from this point forward, A can't be nullptr. Signed-off-by: Larry Gritz <lg@larrygritz.com> Signed-off-by: Peter Kovář <peter.kovar@reflexion.tv>
1 parent a0a74a3 commit 86d40a2

File tree

5 files changed

+12
-3
lines changed

5 files changed

+12
-3
lines changed

src/dpx.imageio/libdpx/WriterInternal.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,11 @@ namespace dpx
203203
// this routine expects a type of U16
204204
template <typename IB, Packing METHOD>
205205
void WritePackedMethodAB_10bit(IB *src, IB *dst, const int len, const bool reverse, BufferAccess &access)
206-
{
206+
{
207+
OIIO_DASSERT(len >= 1);
208+
if (len < 1)
209+
return;
210+
207211
// pack into the same memory space
208212
U32 *dst_u32 = reinterpret_cast<U32*>(dst);
209213

src/libOpenImageIO/imagebufalgo_mad.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ ImageBufAlgo::mad(ImageBuf& dst, Image_or_Const A_, Image_or_Const B_,
147147
A_.swap(B_);
148148
// Get pointers to any image. At least one of A or B must be an image.
149149
const ImageBuf *A = A_.imgptr(), *B = B_.imgptr(), *C = C_.imgptr();
150-
if (!A && !B) {
150+
if (!A) {
151151
dst.errorfmt(
152152
"ImageBufAlgo::mad(): at least one of the first two arguments must be an image");
153153
return false;

src/oiiotool/printinfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ OiioTool::print_info(std::ostream& out, Oiiotool& ot, ImageRec* img,
529529
}
530530

531531
for (int s = 0, nsubimages = img->subimages(); s < nsubimages; ++s) {
532+
DASSERT((opt.native ? img->nativespec(s) : img->spec(s)) != nullptr);
532533
print_info_subimage(out, ot, s, nsubimages, img->miplevels(s),
533534
opt.native ? *img->nativespec(s) : *img->spec(s),
534535
img, nullptr, "", opt, field_re, field_exclude_re,

src/png.imageio/pngoutput.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ PNGOutput::PNGOutput() { init(); }
119119
PNGOutput::~PNGOutput()
120120
{
121121
// Close, if not already done.
122-
close();
122+
try {
123+
close();
124+
} catch (...) {
125+
}
123126
}
124127

125128

src/testtex/testtex.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,7 @@ do_tex_thread_workout(int iterations, int mythread)
14131413
float s = 0.1f, t = 0.1f;
14141414
int nchannels = nchannels_override ? nchannels_override : 3;
14151415
float* result = OIIO_ALLOCA(float, nchannels);
1416+
memset(result, 0, sizeof(float) * nchannels);
14161417
TextureOpt opt;
14171418
initialize_opt(opt);
14181419
float* dresultds = test_derivs ? OIIO_ALLOCA(float, nchannels) : NULL;

0 commit comments

Comments
 (0)