I don't know why this is happening, but when I edit one of my content types, I see the following warnings:

warning: Division by zero in sites/all/modules/fivestar/fivestar.module on line 1427.
warning: Division by zero in sites/all/modules/fivestar/fivestar.module on line 1428

The relevant code is:

...
for ($i = 0; $i <= $element['#stars']; $i++) {
  $this_value = ceil($i * 100/$element['#stars']);
  $next_value = ceil(($i+1) * 100/$element['#stars']);
...

I do not have fivestar enabled for this content type.

Any ideas?

Comments

dleeward’s picture

I'm having the same problem when I use the Five Star CCK field in a view set as a percentage. I noticed that it has been fixed in 6.x. Will it be fixed in 5.x?

ogi’s picture

Not fixed in 6.x-1.13. I have a content type (CCK) and the page Edit for that content type shows the following warning twice. Fivestar is not configured in any way, it's just enabled.

warning: Division by zero in /home/ogi/public_html/acquia/modules/acquia/fivestar/fivestar.module on line 1472.

It's worth noting that I'm using PostgreSQL.

stormsweeper’s picture

I am also getting this in the latest 6.x release - it doesn't seem to break anything, it's just annoying. I'm using prior 5.x versions without the error. I'm also using Postgres, but I will look at the code before I say if that's an issue.

stormsweeper’s picture

StatusFileSize
new678 bytes

The error points to fivestar_expand($element), namely this for loop:

  for ($i = 0; $i <= $element['#stars']; $i++) {
    $this_value = ceil($i * 100/$element['#stars']);
    $next_value = ceil(($i+1) * 100/$element['#stars']);
  
    ...
  }

I presume this is being called by the "preview" widget when editing a type. I added this in just before it:

   if (!isset($element['#stars'])) {
    $element['#stars'] = 5;
  }   

A patch against 6.x-1.13 is attached.

stormsweeper’s picture

StatusFileSize
new675 bytes

And here's an untested patch against 5.x-1.13

quicksketch’s picture

Status: Active » Needs work

Please check the latest development version of Fivestar, this might have already been fixed. The patch needs to be rolled against the latest version regardless.

stormsweeper’s picture

StatusFileSize
new680 bytes
stormsweeper’s picture

Weird, my reply was lost. That patch is against DRUPAL-6--1, I don't have a test 5.x site right now to test out a DRUPAL-5 patch, but the DRUPAL-6--1 branch definitely still has the reported issue, and it would appear the same will be true for DRUPAL-5, looking at the code.

ebeyrent’s picture

I'll check out the D5 code and see if it fixes my issue.

Jn3’s picture

Version: 5.x-1.13 » 6.x-1.13

Problem still there as of latest version.

warning: Division by zero in .../sites/all/modules/fivestar/fivestar_field.inc on line 291.

quicksketch’s picture

Jn3, the latest version is the development version, which contains 7 months of fixes that aren't in the 1.13 version. A new release of Fivestar should be coming soon, but in the mean time, I'd appreciate if you could try out the development version and see if this has been fixed there.

quicksketch’s picture

Status: Needs work » Fixed

Please reopen if this problem can be reproduced in the 1.15 version.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.