[1.7.1] Division by zero error

Official announcements concerning bugs and fixes in the WoWRoster package
Posting is restricted to Forum Moderators

[1.7.1] Division by zero error

Postby zanix » Wed Oct 25, 2006 1:58 pm

When a player has 0 exp, you may get 'Division by zero' errors on index.php and char.php

Exp isn't checked if it's zero and we all know what happens when you try to divide by 0...

Here is the manual fix
Or you can download the patched files
[1.7.1] exp 'Division by zero' error
NOTE: The Download includes the [1.7.1] Riding Skill Errors fix

memberslist.php
Find around line 696
Code: Select all
$percent_exp =  round(($current/$max)*100); 

Replace with
Code: Select all
$percent_exp = ($max round(($current/$max)*100) : 0); 



lib/char.php
Find around lines 45-57
(entire function)
Code: Select all
    function printXP()
    {
        list(
$current$max) =
        
explode':'$this->data['exp'] );

        
$perc='';
        if (
$current 0)
        {
            
$perc round(($current $max)* 2481);
        }
        return 
$perc;
    } 

Replace with
Code: Select all
    function printXP()
    {
        list(
$current$max) = explode':'$this->data['exp'] );

        
$perc 0;
        if( 
$max )
        {
            
$perc round(($current $max)* 2480);
        }
        return 
$perc;
    } 


Find around lines 1493-1505
Code: Select all
    $expbar_width $this->printXP();
    list(
$xp$xplevel$xprest) = explode(':',$this->data['exp']);
    if (
$xplevel != '0' || $xplevel != '')
    {
        if( 
$xprest )
        {
            
$expbar_text $xp.'/'.$xplevel.' : '.$xprest.' ('.round($xp/$xplevel*100).'%)';
        }
        else
        {
            
$expbar_text $xp.'/'.$xplevel.' ('.round($xp/$xplevel*100).'%)';
        }
    } 

Replace with
Code: Select all
    $expbar_width $this->printXP();
    list(
$xp$xplevel$xprest) = explode(':',$this->data['exp']);
    if (
$xplevel != '0' && $xplevel != '')
    {
        
$exp_percent = ( $xplevel round(($xp/$xplevel)*100) : 0);
        if( 
$xprest )
        {
            
$expbar_text $xp.'/'.$xplevel.' : '.$xprest.' ('.$exp_percent.'%)';
        }
        else
        {
            
$expbar_text $xp.'/'.$xplevel.' ('.$exp_percent.'%)';
        }
    } 
Attachments
divbyzero.jpg
Division by zero error
divbyzero.jpg (50.95 KiB) Viewed 1998 times
Last edited by zanix on Wed Oct 25, 2006 2:22 pm, edited 2 times in total.
Read the Forum Rules, the WiKi, and Search before posting!
WoWRoster v2.1 - SigGen v0.3.3.523 - WoWRosterDF
User avatar
zanix
Admin
Admin
WoWRoster.net Dev Team
WoWRoster.net Dev Team
UA/UU Developer
UA/UU Developer
 
Posts: 5546
Joined: Mon Jul 03, 2006 8:29 am
Location: Idaho Falls, Idaho
Realm: Doomhammer (PvE) - US

Return to Official Bugs & Updates

Who is online

Users browsing this forum: No registered users and 0 guests

cron