diff --git a/MagickCore/fx.c b/MagickCore/fx.c
index 4182835..ff295b8 100644
--- a/MagickCore/fx.c
+++ b/MagickCore/fx.c
@@ -1410,7 +1410,8 @@
   length=GetImageListLength(fx_info->images);
   while (i < 0)
     i+=(ssize_t) length;
-  i%=length;
+  if (length != 0)
+    i%=length;
   image=GetImageFromList(fx_info->images,i);
   if (image == (Image *) NULL)
     {