[CF-Devel] Suspicious code in server/skills.c

crossfire-devel at archives.real-time.com crossfire-devel at archives.real-time.com
Sun Apr 25 01:18:56 CDT 2004


Andreas Kirschbaum wrote:
>
     
      In server/skills.c is a suspicious calculation:
     
     >
     
     
     >
     
          throw_ob->stats.wc = 25-dex_bonus[op->stats.Dex?dex_bonus[op->stats.Dex]:0]-thaco_bonus[eff_str]-skill->level;
     
     >
     
     
     >
     
      Essentially it calculates:
     
     >
     
     
     >
     
          dex_bonus[dex_bonus[Dex]]
     
     >
     
     
     >
     
      This can't be correct because
     
     >
     
     
     >
     
       1. dex_bonus[] contains some negative values so it may access
     
     >
     
          dex_bonus[-1]
     
     >
     
     
     >
     
       2. dex_bonus[1] == -3 so "Dex ? dex_bonus[Dex] : 0" is not a
     
     >
     
          sensible (monotonic increasing) function
     
     >
     
     
     >
     
       3. dex_bonus maps "Dex" into "Wc" so "dex_bonus[Wc]" is incorrect
     
     >
     
     
     >
     
     
     >
     
      A possible solution could be
     
     >
     
     
     >
     
          throw_ob->stats.wc = 25-dex_bonus[op->stats.Dex]-thaco_bonus[eff_str]-skill->level;
     
     >
     
     
     >
     
      Is this the intended behavior?
     
     
  I've made the change you suggested - I think that is the proper behaviour - 
I'm not sure what the intention of the original code was.  Often times, there 
will be syntax like op->stats.dex?op->stats.dex:1, but the above mentioned code 
wasn't doing that.  And the 0 values for are the stat bonus arrays is properly 
intialized, so no harm using a 0 stat of dex.


_______________________________________________
crossfire-devel mailing list
     
     crossfire-devel at lists.real-time.com
     
     
     https://mailman.real-time.com/mailman/listinfo/crossfire-devel
     
     
    


More information about the crossfire mailing list