Author Topic: maybe have a unobvious bug?  (Read 1215 times)

player

  • Wayfarer
  • *
  • Posts: 4
    • View Profile
maybe have a unobvious bug?
« on: December 12, 2006, 06:53:25 am »
c:\development\planeshift\src\npcclient\npcbehave.cpp(837) : warning C4715: 'Behavior::ResumeScript' : not all control paths return a value

about warning C4715 of VC++2005
http://msdn2.microsoft.com/en-us/library/ms909205.aspx

AryHann

  • Veteran
  • *
  • Posts: 1244
  • WonderWoman
    • View Profile
Re: maybe have a unobvious bug?
« Reply #1 on: December 12, 2006, 07:34:08 am »
Thank you for pointing that out!
I was trying to fix such warning but I have no details about the function characteristics, so I was waiting for the author to reply :-)
Maybe he will do it here ;)
AryHann

http://www.reflex.lth.se/culture/annelov - Virtual Annelöv -
Engine Dep. - One of Talad's Angels - Aka ww & Ahrijani's Goddess

acraig

  • Administrator
  • Veteran
  • *
  • Posts: 1562
    • View Profile
Re: maybe have a unobvious bug?
« Reply #2 on: December 12, 2006, 07:43:22 pm »
Well, here's the function in question and my thoughts.

Code: [Select]
bool Behavior::ResumeScript(NPC *npc,EventManager *eventmgr)
{
    npc->Printf("Resuming behavior %s at step %d.",name.GetData(),current_step);
    if (current_step < sequence.Length())
    {
        if (sequence[current_step]->CompleteOperation(npc,eventmgr))
        {
            current_step++;
            return RunScript(npc,eventmgr,false);
        }     
    }
    else
    {
        current_step=0;
        return RunScript(npc,eventmgr,false);
    }
}

You can see that there is case where no return value is sent ( ie the first if passes and nested if fails ).  So the best way to solve this I think is to add a return true at the end.  I am guessing true because RunScript() will return true if the behaviour is complete.  So if there is nothing to do we can return true.
----------
Andrew
"For all I know, she's lying, everyone's lying; welcome to the Internet"