From: Ilya Shipitsin Date: Thu, 30 Aug 2018 10:16:20 +0000 (+0500) Subject: resolve several null pointer dereferences X-Git-Tag: 7.0.8-12~109 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e0d07ae0640f36f8c952f66692fc0fd5e143d511;p=imagemagick resolve several null pointer dereferences found by cppcheck [MagickCore/draw.c:881] -> [MagickCore/draw.c:879]: (warning) Either the condition 'draw_info!=(DrawInfo*)NULL' is redundant or there is possible null pointer dereference: draw_info. [MagickCore/fx.c:3966] -> [MagickCore/fx.c:3964]: (warning) Either the condition 'image!=(Image*)NULL' is redundant or there is possible null pointer dereference: image. [MagickCore/fx.c:5009] -> [MagickCore/fx.c:5006]: (warning) Either the condition 'right_image!=(const Image*)NULL' is redundant or there is possible null pointer dereference: right_image. [MagickCore/montage.c:168] -> [MagickCore/montage.c:166]: (warning) Either the condition 'montage_info!=(MontageInfo*)NULL' is redundant or there is possible null pointer dereference: montage_info. [MagickCore/montage.c:416] -> [MagickCore/montage.c:415]: (warning) Either the condition 'master_list==(Image**)NULL' is redundant or there is possible null pointer dereference: image_list. [MagickCore/nt-base.c:1792] -> [MagickCore/nt-base.c:1797]: (warning) Either the condition 'entry!=(DIR*)NULL' is redundant or there is possible null pointer dereference: entry. [MagickWand/drawing-wand.c:177] -> [MagickWand/drawing-wand.c:175]: (warning) Either the condition 'wand!=(DrawingWand*)NULL' is redundant or there is possible null pointer dereference: wand. [MagickWand/drawing-wand.c:4540] -> [MagickWand/drawing-wand.c:4538]: (warning) Either the condition 'wand!=(DrawingWand*)NULL' is redundant or there is possible null pointer dereference: wand. [MagickWand/drawing-wand.c:4682] -> [MagickWand/drawing-wand.c:4680]: (warning) Either the condition 'wand!=(DrawingWand*)NULL' is redundant or there is possible null pointer dereference: wand. [coders/msl.c:575] -> [coders/msl.c:555]: (warning) Either the condition 'image==(Image*)NULL' is redundant or there is possible null pointer dereference: image. --- diff --git a/MagickCore/draw.c b/MagickCore/draw.c index 297407bc4..b6e5a8fd4 100644 --- a/MagickCore/draw.c +++ b/MagickCore/draw.c @@ -876,9 +876,9 @@ static PathInfo *ConvertPrimitiveToPath(const PrimitiveInfo *primitive_info) */ MagickExport DrawInfo *DestroyDrawInfo(DrawInfo *draw_info) { + assert(draw_info != (DrawInfo *) NULL); if (draw_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); - assert(draw_info != (DrawInfo *) NULL); assert(draw_info->signature == MagickCoreSignature); if (draw_info->primitive != (char *) NULL) draw_info->primitive=DestroyString(draw_info->primitive); diff --git a/MagickCore/fx.c b/MagickCore/fx.c index 12dcc0996..bcf27f852 100644 --- a/MagickCore/fx.c +++ b/MagickCore/fx.c @@ -3961,9 +3961,9 @@ MagickExport MagickBooleanType PlasmaImage(Image *image, RandomInfo *random_info; + assert(image != (Image *) NULL); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); - assert(image != (Image *) NULL); assert(image->signature == MagickCoreSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); @@ -5006,7 +5006,6 @@ MagickExport Image *StereoAnaglyphImage(const Image *left_image, assert(right_image->signature == MagickCoreSignature); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickCoreSignature); - assert(right_image != (const Image *) NULL); image=left_image; if ((left_image->columns != right_image->columns) || (left_image->rows != right_image->rows)) diff --git a/MagickCore/montage.c b/MagickCore/montage.c index a18bca35a..fd83546c6 100644 --- a/MagickCore/montage.c +++ b/MagickCore/montage.c @@ -163,9 +163,9 @@ MagickExport MontageInfo *CloneMontageInfo(const ImageInfo *image_info, */ MagickExport MontageInfo *DestroyMontageInfo(MontageInfo *montage_info) { + assert(montage_info != (MontageInfo *) NULL); if (montage_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); - assert(montage_info != (MontageInfo *) NULL); assert(montage_info->signature == MagickCoreSignature); if (montage_info->geometry != (char *) NULL) montage_info->geometry=(char *) @@ -411,10 +411,10 @@ MagickExport Image *MontageImageList(const ImageInfo *image_info, assert(exception->signature == MagickCoreSignature); number_images=GetImageListLength(images); master_list=ImageListToArray(images,exception); - image_list=master_list; - image=image_list[0]; if (master_list == (Image **) NULL) ThrowImageException(ResourceLimitError,"MemoryAllocationFailed"); + image_list=master_list; + image=image_list[0]; thumbnail=NewImageList(); for (i=0; i < (ssize_t) number_images; i++) { diff --git a/MagickCore/nt-base.c b/MagickCore/nt-base.c index ae8560007..ca785a06c 100644 --- a/MagickCore/nt-base.c +++ b/MagickCore/nt-base.c @@ -1789,11 +1789,8 @@ MagickPrivate DIR *NTOpenDirectory(const char *path) MagickPathExtent-wcslen(file_specification)-1) == (wchar_t*) NULL) return((DIR *) NULL); entry=(DIR *) AcquireCriticalMemory(sizeof(DIR)); - if (entry != (DIR *) NULL) - { - entry->firsttime=TRUE; - entry->hSearch=FindFirstFileW(file_specification,&entry->Win32FindData); - } + entry->firsttime=TRUE; + entry->hSearch=FindFirstFileW(file_specification,&entry->Win32FindData); if (entry->hSearch == INVALID_HANDLE_VALUE) { if(wcsncat(file_specification,L"*.*", diff --git a/coders/msl.c b/coders/msl.c index 0ecfcf1ae..dee0526ce 100644 --- a/coders/msl.c +++ b/coders/msl.c @@ -552,7 +552,8 @@ static void MSLPushImage(MSLInfo *msl_info,Image *image) ssize_t n; - (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); + if (image != (Image *) NULL) + (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); assert(msl_info != (MSLInfo *) NULL); msl_info->n++; n=msl_info->n;