The International Simutrans Forum

Simutrans Extended => Simutrans-Extended development => Topic started by: knightly on July 07, 2009, 07:04:58 am

Title: [Bug v4.6] Not All Control Paths Return a Value
Post by: knightly on July 07, 2009, 07:04:58 am
Hi James,

When I compiled ST EXP, I noticed the following warning :

Quote
e:\programs\simutrans_exp_src\source\simwerkz.cc(1150) : warning C4715: 'wkz_marker_t::work' : not all control paths return a value

Probably, the last return statement is misplaced -- it should be between the last and the 2nd last closing brackets, right?

Quote
const char *wkz_marker_t::work( karte_t *welt, spieler_t *sp, koord3d pos )
{
   if(welt->ist_in_kartengrenzen(pos.get_2d())) {
      grund_t *gr = welt->lookup(pos.get_2d())->get_kartenboden();

      if (gr)
      {
         // check for underground mode
         if (grund_t::underground_mode == grund_t::ugm_all ||
            (grund_t::underground_mode == grund_t::ugm_level && gr->get_hoehe()>grund_t::underground_level)) {
               return "";
         }
         if(gr && !gr->get_text())
         {
            const ding_t* thing = gr->obj_bei(0);
            const label_t* l = gr->find<label_t>();

            if(thing == NULL  ||  thing->get_besitzer() == sp  ||  (spieler_t::check_owner(thing->get_besitzer(), sp)  &&  (thing->get_typ() != ding_t::gebaeude)))
            {
               if(!sp->can_afford(welt->get_einstellungen()->cst_buy_land))
               {   
                  return CREDIT_MESSAGE;
               }
               gr->obj_add(new label_t(welt, gr->get_pos(), sp, "\0"));
               gr->find<label_t>()->zeige_info();
               return "";
            }
         }
      }
   return "Das Feld gehoert\neinem anderen Spieler\n";
   }
}
Title: Re: [Bug v4.6] Not All Control Paths Return a Value
Post by: Bernd Gabriel on July 07, 2009, 09:40:41 pm
The text of the last returns says "Field is owned by another player". This wold be a missleading return for the outermost {}. It should sound like "Invalid coordidate beyond world bounds" or similar.
Title: Re: [Bug v4.6] Not All Control Paths Return a Value
Post by: jamespetts on July 07, 2009, 10:36:49 pm
In which case, I suspect that the code is superfluous in any event - deleting fields is now allowed unless the number of fields is at or below the minimum, in which case a special error message appears notifying the player of the fact. So this error message seems to be a remnant of an earlier time (and therefore an issue from Simutrans-Standard rather than Simutrans-Experimental).
Title: Re: [Bug v4.6] Not All Control Paths Return a Value
Post by: knightly on July 08, 2009, 06:10:50 am

I didn't have time to study the code. What I want to point out is only that, all control paths should return something valid. :)