[Dnsmasq-discuss] goto's to the middle of if's in tftp.c...

Carlos Carvalho carlos at fisica.ufpr.br
Thu Feb 1 19:44:33 GMT 2007


Simon Kelley (simon at thekelleys.org.uk) wrote on 1 February 2007 16:51:
 >Carlos Carvalho wrote:
 >> There are some goto's to the middle of if's and else's in tftp.c. Such
 >> jumps could perhaps be changed to a place less susceptible to
 >> confusion... Since it's a new piece of code it might still be open to
 >> small revisions. It may cost some extra if's but it won't make a
 >> difference in performance.
 >
 >If anyone can come up with a nicer solution, I'd be happy to take it,
 >but I think that's a good use for gotos. The code identifies a couple of
 >error conditions and the way to handle them, so it's obvious what's
 >going on. When the same error conditions are encountered later, they are
 >handled by gotos to the previously defined error handling code - it's a
 >standard programming practise.

Yes but I'm suggesting placing the labels in another point, not
removing the gotos. Something like

deeply-nested if-else {
              if (<permission error>) {
		 err_perm=1
		 goto error;
              }
              the same for oops
              ...
           } } } } .... }

error:
   if (err_perm)
      len = tftp_err(ERR_PERM, packet, _("cannot access %s: %s"),
	   daemon->namebuff);
   else if (err_oops)
      len = tftp_err(ERR_NOTDEF, packet, _("cannot read %s: %s"),
	   daemon->namebuff);

    while (sendto(transfer->sockfd...



More information about the Dnsmasq-discuss mailing list