From 78aac0995a3503e731a10e468eb105fa63a260e0 Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 25 Jun 2013 10:18:35 +0100 Subject: [PATCH] Fixes for some clang static analysis warnings. --- .../ComponentEditor/jucer_ComponentLayout.cpp | 2 ++ .../paintelements/jucer_FillType.h | 1 + .../paintelements/jucer_PaintElementPath.cpp | 3 +++ .../ui/jucer_ComponentLayoutEditor.cpp | 2 ++ .../ComponentEditor/ui/jucer_EditingPanelBase.cpp | 2 ++ .../ui/jucer_ResourceEditorPanel.cpp | 1 + .../codecs/flac/libFLAC/stream_encoder.c | 6 +++--- .../codecs/oggvorbis/libvorbis-1.3.2/lib/floor1.c | 4 ++-- .../oggvorbis/libvorbis-1.3.2/lib/vorbisfile.c | 5 ++++- modules/juce_core/containers/juce_Array.h | 15 +++++++++++---- .../containers/juce_ArrayAllocationBase.h | 2 ++ modules/juce_core/containers/juce_OwnedArray.h | 15 ++++++++++++--- .../containers/juce_ReferenceCountedArray.h | 3 +++ modules/juce_core/system/juce_PlatformDefs.h | 12 +++++++++++- modules/juce_graphics/image_formats/pnglib/png.c | 4 ++-- .../juce_graphics/image_formats/pnglib/pngrutil.c | 2 +- 16 files changed, 62 insertions(+), 17 deletions(-) diff --git a/extras/Introjucer/Source/ComponentEditor/jucer_ComponentLayout.cpp b/extras/Introjucer/Source/ComponentEditor/jucer_ComponentLayout.cpp index a8ab6044e0..6602b19201 100644 --- a/extras/Introjucer/Source/ComponentEditor/jucer_ComponentLayout.cpp +++ b/extras/Introjucer/Source/ComponentEditor/jucer_ComponentLayout.cpp @@ -728,6 +728,7 @@ String ComponentLayout::getComponentMemberVariableName (Component* comp) const void ComponentLayout::setComponentMemberVariableName (Component* comp, const String& newName) { + jassert (comp != nullptr); const String oldName (getComponentMemberVariableName (comp)); comp->getProperties().set ("memberName", String::empty); @@ -782,6 +783,7 @@ String ComponentLayout::getComponentVirtualClassName (Component* comp) const void ComponentLayout::setComponentVirtualClassName (Component* comp, const String& newName) { + jassert (comp != nullptr); const String name (CodeHelpers::makeValidIdentifier (newName, false, false, true)); if (name != getComponentVirtualClassName (comp)) diff --git a/extras/Introjucer/Source/ComponentEditor/paintelements/jucer_FillType.h b/extras/Introjucer/Source/ComponentEditor/paintelements/jucer_FillType.h index 4582874480..0754bc6605 100644 --- a/extras/Introjucer/Source/ComponentEditor/paintelements/jucer_FillType.h +++ b/extras/Introjucer/Source/ComponentEditor/paintelements/jucer_FillType.h @@ -96,6 +96,7 @@ public: } else if (mode == imageBrush) { + jassert (document != nullptr); loadImage (document); Rectangle r (imageAnchor.getRectangle (parentArea, document->getComponentLayout())); diff --git a/extras/Introjucer/Source/ComponentEditor/paintelements/jucer_PaintElementPath.cpp b/extras/Introjucer/Source/ComponentEditor/paintelements/jucer_PaintElementPath.cpp index 3a5e7d7875..987411a99f 100644 --- a/extras/Introjucer/Source/ComponentEditor/paintelements/jucer_PaintElementPath.cpp +++ b/extras/Introjucer/Source/ComponentEditor/paintelements/jucer_PaintElementPath.cpp @@ -977,7 +977,10 @@ bool PaintElementPath::getPoint (int index, int pointNumber, double& x, double& const PathPoint* const p = points [index]; if (p == nullptr) + { + x = y = 0; return false; + } jassert (pointNumber < 3 || p->type == Path::Iterator::cubicTo); jassert (pointNumber < 2 || p->type == Path::Iterator::cubicTo || p->type == Path::Iterator::quadraticTo); diff --git a/extras/Introjucer/Source/ComponentEditor/ui/jucer_ComponentLayoutEditor.cpp b/extras/Introjucer/Source/ComponentEditor/ui/jucer_ComponentLayoutEditor.cpp index 8cf59583c1..59223e70ee 100644 --- a/extras/Introjucer/Source/ComponentEditor/ui/jucer_ComponentLayoutEditor.cpp +++ b/extras/Introjucer/Source/ComponentEditor/ui/jucer_ComponentLayoutEditor.cpp @@ -215,6 +215,8 @@ void ComponentLayoutEditor::refreshAllComponents() for (int i = layout.getNumComponents(); --i >= 0;) { Component* const c = layout.getComponent (i); + jassert (c != nullptr); + ComponentOverlayComponent* overlay = getOverlayCompFor (c); bool isNewOverlay = false; diff --git a/extras/Introjucer/Source/ComponentEditor/ui/jucer_EditingPanelBase.cpp b/extras/Introjucer/Source/ComponentEditor/ui/jucer_EditingPanelBase.cpp index 4d72b8d638..f69d31c9de 100644 --- a/extras/Introjucer/Source/ComponentEditor/ui/jucer_EditingPanelBase.cpp +++ b/extras/Introjucer/Source/ComponentEditor/ui/jucer_EditingPanelBase.cpp @@ -218,6 +218,8 @@ void EditingPanelBase::setZoom (double newScale, int anchorX, int anchorY) magnifier->setScaleFactor (newScale); resized(); + + jassert (viewport != nullptr); anchor = viewport->getLocalPoint (editor, anchor); viewport->setViewPosition (jlimit (0, jmax (0, viewport->getViewedComponent()->getWidth() - viewport->getViewWidth()), diff --git a/extras/Introjucer/Source/ComponentEditor/ui/jucer_ResourceEditorPanel.cpp b/extras/Introjucer/Source/ComponentEditor/ui/jucer_ResourceEditorPanel.cpp index 3940b2faf0..27ca236004 100644 --- a/extras/Introjucer/Source/ComponentEditor/ui/jucer_ResourceEditorPanel.cpp +++ b/extras/Introjucer/Source/ComponentEditor/ui/jucer_ResourceEditorPanel.cpp @@ -161,6 +161,7 @@ int ResourceEditorPanel::getColumnAutoSizeWidth (int columnId) for (int i = document.getResources().size(); --i >= 0;) { const BinaryResources::BinaryResource* const r = document.getResources() [i]; + jassert (r != nullptr); String text; if (columnId == 1) diff --git a/modules/juce_audio_formats/codecs/flac/libFLAC/stream_encoder.c b/modules/juce_audio_formats/codecs/flac/libFLAC/stream_encoder.c index b4eb0ea6f1..2db9832b5d 100644 --- a/modules/juce_audio_formats/codecs/flac/libFLAC/stream_encoder.c +++ b/modules/juce_audio_formats/codecs/flac/libFLAC/stream_encoder.c @@ -2660,7 +2660,7 @@ void update_metadata_(const FLAC__StreamEncoder *encoder) b[3] = (FLAC__byte)xx; xx >>= 8; b[2] = (FLAC__byte)xx; xx >>= 8; b[1] = (FLAC__byte)xx; xx >>= 8; - b[0] = (FLAC__byte)xx; xx >>= 8; + b[0] = (FLAC__byte)xx; //xx >>= 8; xx = encoder->private_->seek_table->points[i].stream_offset; b[15] = (FLAC__byte)xx; xx >>= 8; b[14] = (FLAC__byte)xx; xx >>= 8; @@ -2669,10 +2669,10 @@ void update_metadata_(const FLAC__StreamEncoder *encoder) b[11] = (FLAC__byte)xx; xx >>= 8; b[10] = (FLAC__byte)xx; xx >>= 8; b[9] = (FLAC__byte)xx; xx >>= 8; - b[8] = (FLAC__byte)xx; xx >>= 8; + b[8] = (FLAC__byte)xx; //xx >>= 8; x = encoder->private_->seek_table->points[i].frame_samples; b[17] = (FLAC__byte)x; x >>= 8; - b[16] = (FLAC__byte)x; x >>= 8; + b[16] = (FLAC__byte)x; //x >>= 8; if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) { encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; return; diff --git a/modules/juce_audio_formats/codecs/oggvorbis/libvorbis-1.3.2/lib/floor1.c b/modules/juce_audio_formats/codecs/oggvorbis/libvorbis-1.3.2/lib/floor1.c index 5a8bd92eca..8ea1978962 100644 --- a/modules/juce_audio_formats/codecs/oggvorbis/libvorbis-1.3.2/lib/floor1.c +++ b/modules/juce_audio_formats/codecs/oggvorbis/libvorbis-1.3.2/lib/floor1.c @@ -471,7 +471,7 @@ static int fit_line(lsfit_acc *a,int fits,int *y0,int *y1, xb+= x0; yb+= *y0; x2b+= x0 * x0; - y2b+= *y0 * *y0; + //y2b+= *y0 * *y0; xyb+= *y0 * x0; bn++; } @@ -480,7 +480,7 @@ static int fit_line(lsfit_acc *a,int fits,int *y0,int *y1, xb+= x1; yb+= *y1; x2b+= x1 * x1; - y2b+= *y1 * *y1; + //y2b+= *y1 * *y1; xyb+= *y1 * x1; bn++; } diff --git a/modules/juce_audio_formats/codecs/oggvorbis/libvorbis-1.3.2/lib/vorbisfile.c b/modules/juce_audio_formats/codecs/oggvorbis/libvorbis-1.3.2/lib/vorbisfile.c index 5c344dd81e..79b668855c 100644 --- a/modules/juce_audio_formats/codecs/oggvorbis/libvorbis-1.3.2/lib/vorbisfile.c +++ b/modules/juce_audio_formats/codecs/oggvorbis/libvorbis-1.3.2/lib/vorbisfile.c @@ -853,7 +853,7 @@ static int _fetch_and_process_packet(OggVorbis_File *vf, if(ret)return(ret); vf->current_serialno=vf->os.serialno; vf->current_link++; - link=0; + //link=0; } } } @@ -1561,6 +1561,7 @@ int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){ break; }else result=ogg_stream_packetout(&vf->os,NULL); + (void) result; } } } @@ -2158,6 +2159,8 @@ static void _ov_getlap(OggVorbis_File *vf,vorbis_info *vi,vorbis_dsp_state *vd, memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples); lapcount+=samples; } + + (void) lapcount; } } diff --git a/modules/juce_core/containers/juce_Array.h b/modules/juce_core/containers/juce_Array.h index 206dff0cc6..6940344620 100644 --- a/modules/juce_core/containers/juce_Array.h +++ b/modules/juce_core/containers/juce_Array.h @@ -235,8 +235,14 @@ public: ElementType operator[] (const int index) const { const ScopedLockType lock (getLock()); - return isPositiveAndBelow (index, numUsed) ? data.elements [index] - : ElementType(); + + if (isPositiveAndBelow (index, numUsed)) + { + jassert (data.elements != nullptr); + return data.elements [index]; + } + + return ElementType(); } /** Returns one of the elements in the array, without checking the index passed in. @@ -251,7 +257,7 @@ public: inline ElementType getUnchecked (const int index) const { const ScopedLockType lock (getLock()); - jassert (isPositiveAndBelow (index, numUsed)); + jassert (isPositiveAndBelow (index, numUsed) && data.elements != nullptr); return data.elements [index]; } @@ -267,7 +273,7 @@ public: inline ElementType& getReference (const int index) const noexcept { const ScopedLockType lock (getLock()); - jassert (isPositiveAndBelow (index, numUsed)); + jassert (isPositiveAndBelow (index, numUsed) && data.elements != nullptr); return data.elements [index]; } @@ -388,6 +394,7 @@ public: { const ScopedLockType lock (getLock()); data.ensureAllocatedSize (numUsed + 1); + jassert (data.elements != nullptr); if (isPositiveAndBelow (indexToInsertAt, numUsed)) { diff --git a/modules/juce_core/containers/juce_ArrayAllocationBase.h b/modules/juce_core/containers/juce_ArrayAllocationBase.h index d19887f611..1499564eb5 100644 --- a/modules/juce_core/containers/juce_ArrayAllocationBase.h +++ b/modules/juce_core/containers/juce_ArrayAllocationBase.h @@ -108,6 +108,8 @@ public: { if (minNumElements > numAllocated) setAllocatedSize ((minNumElements + minNumElements / 2 + 8) & ~7); + + jassert (numAllocated <= 0 || elements != nullptr); } /** Minimises the amount of storage allocated so that it's no more than diff --git a/modules/juce_core/containers/juce_OwnedArray.h b/modules/juce_core/containers/juce_OwnedArray.h index f3cdbea1d4..ee25d2172a 100644 --- a/modules/juce_core/containers/juce_OwnedArray.h +++ b/modules/juce_core/containers/juce_OwnedArray.h @@ -129,8 +129,13 @@ public: inline ObjectClass* operator[] (const int index) const noexcept { const ScopedLockType lock (getLock()); - return isPositiveAndBelow (index, numUsed) ? data.elements [index] - : static_cast (nullptr); + if (isPositiveAndBelow (index, numUsed)) + { + jassert (data.elements != nullptr); + return data.elements [index]; + } + + return nullptr; } /** Returns a pointer to the object at this index in the array, without checking whether the index is in-range. @@ -141,7 +146,7 @@ public: inline ObjectClass* getUnchecked (const int index) const noexcept { const ScopedLockType lock (getLock()); - jassert (isPositiveAndBelow (index, numUsed)); + jassert (isPositiveAndBelow (index, numUsed) && data.elements != nullptr); return data.elements [index]; } @@ -248,6 +253,7 @@ public: { const ScopedLockType lock (getLock()); data.ensureAllocatedSize (numUsed + 1); + jassert (data.elements != nullptr); data.elements [numUsed++] = const_cast (newObject); } @@ -279,6 +285,7 @@ public: indexToInsertAt = numUsed; data.ensureAllocatedSize (numUsed + 1); + jassert (data.elements != nullptr); ObjectClass** const e = data.elements + indexToInsertAt; const int numToMove = numUsed - indexToInsertAt; @@ -431,6 +438,7 @@ public: numElementsToAdd = arrayToAddFrom.size() - startIndex; data.ensureAllocatedSize (numUsed + numElementsToAdd); + jassert (data.elements != nullptr); while (--numElementsToAdd >= 0) { @@ -471,6 +479,7 @@ public: numElementsToAdd = arrayToAddFrom.size() - startIndex; data.ensureAllocatedSize (numUsed + numElementsToAdd); + jassert (data.elements != nullptr); while (--numElementsToAdd >= 0) { diff --git a/modules/juce_core/containers/juce_ReferenceCountedArray.h b/modules/juce_core/containers/juce_ReferenceCountedArray.h index 96583114d2..c792d8766c 100644 --- a/modules/juce_core/containers/juce_ReferenceCountedArray.h +++ b/modules/juce_core/containers/juce_ReferenceCountedArray.h @@ -297,6 +297,7 @@ public: { const ScopedLockType lock (getLock()); data.ensureAllocatedSize (numUsed + 1); + jassert (data.elements != nullptr); data.elements [numUsed++] = newObject; if (newObject != nullptr) @@ -327,6 +328,7 @@ public: indexToInsertAt = numUsed; data.ensureAllocatedSize (numUsed + 1); + jassert (data.elements != nullptr); ObjectClass** const e = data.elements + indexToInsertAt; const int numToMove = numUsed - indexToInsertAt; @@ -393,6 +395,7 @@ public: else { data.ensureAllocatedSize (numUsed + 1); + jassert (data.elements != nullptr); data.elements [numUsed++] = newObject; } } diff --git a/modules/juce_core/system/juce_PlatformDefs.h b/modules/juce_core/system/juce_PlatformDefs.h index 12f5b1de6c..487cb686e0 100644 --- a/modules/juce_core/system/juce_PlatformDefs.h +++ b/modules/juce_core/system/juce_PlatformDefs.h @@ -83,6 +83,16 @@ #define juce_breakDebugger { __asm int 3 } #endif +#if JUCE_CLANG && defined (__has_feature) && ! defined (JUCE_ANALYZER_NORETURN) + #if __has_feature (attribute_analyzer_noreturn) + inline void __attribute__((analyzer_noreturn)) juce_assert_noreturn() {} + #define JUCE_ANALYZER_NORETURN juce_assert_noreturn(); + #endif +#endif + +#ifndef JUCE_ANALYZER_NORETURN + #define JUCE_ANALYZER_NORETURN +#endif //============================================================================== #if JUCE_DEBUG || DOXYGEN @@ -97,7 +107,7 @@ It is only compiled in a debug build, (unless JUCE_LOG_ASSERTIONS is enabled for your build). @see jassert */ - #define jassertfalse { juce_LogCurrentAssertion; if (juce::juce_isRunningUnderDebugger()) juce_breakDebugger; } + #define jassertfalse { juce_LogCurrentAssertion; if (juce::juce_isRunningUnderDebugger()) juce_breakDebugger; JUCE_ANALYZER_NORETURN } //============================================================================== /** Platform-independent assertion macro. diff --git a/modules/juce_graphics/image_formats/pnglib/png.c b/modules/juce_graphics/image_formats/pnglib/png.c index e8589daf93..67e7e2ef6a 100644 --- a/modules/juce_graphics/image_formats/pnglib/png.c +++ b/modules/juce_graphics/image_formats/pnglib/png.c @@ -200,7 +200,7 @@ png_user_version_check(png_structrp png_ptr, png_const_charp user_png_ver) "Application built with libpng-"); pos = png_safecat(m, (sizeof m), pos, user_png_ver); pos = png_safecat(m, (sizeof m), pos, " but running with "); - pos = png_safecat(m, (sizeof m), pos, png_libpng_ver); + png_safecat(m, (sizeof m), pos, png_libpng_ver); png_warning(png_ptr, m); #endif @@ -1720,7 +1720,7 @@ png_icc_profile_error(png_const_structrp png_ptr, png_colorspacerp colorspace, } # endif /* The 'reason' is an arbitrary message, allow +79 maximum 195 */ - pos = png_safecat(message, (sizeof message), pos, reason); + png_safecat(message, (sizeof message), pos, reason); /* This is recoverable, but make it unconditionally an app_error on write to * avoid writing invalid ICC profiles into PNG files. (I.e. we handle them diff --git a/modules/juce_graphics/image_formats/pnglib/pngrutil.c b/modules/juce_graphics/image_formats/pnglib/pngrutil.c index 6f94f51fdb..7671ec46d0 100644 --- a/modules/juce_graphics/image_formats/pnglib/pngrutil.c +++ b/modules/juce_graphics/image_formats/pnglib/pngrutil.c @@ -3862,7 +3862,7 @@ png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row, if (pb < pa) pa = pb, a = b; if (pc < pa) a = c; - c = b; + //c = b; a += *row; *row++ = (png_byte)a; }