News:

Simutrans Sites
Know our official sites. Find tools and resources for Simutrans.

[Bug v4.6] Not All Control Paths Return a Value

Started by knightly, July 07, 2009, 07:04:58 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

knightly

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";
   }
}

Bernd Gabriel

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.
The journey is the reward!

jamespetts

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).
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

knightly


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. :)