[asterisk-dev] Strange code in chan_zap.c ?

Tony Mountifield tony at softins.clara.co.uk
Tue Oct 31 09:48:04 MST 2006


While working through chan_zap.c for a particular issue, I came across
the following code, which, although unrelated to what I was looking for,
didn't look right (this is one case within a switch statement):

	/* FGD MF *Must* wait for wink */
	if (!ast_strlen_zero(p->dop.dialstr))
		res = ioctl(p->subs[SUB_REAL].zfd, ZT_DIAL, &p->dop);
	else if (res < 0) {
		ast_log(LOG_WARNING, "Unable to initiate dialing on trunk channel %d\n", p->channel);
		p->dop.dialstr[0] = '\0';
		return NULL;
	} else
		ast_log(LOG_DEBUG, "Sent deferred digit string: %s\n", p->dop.dialstr);
	p->dop.dialstr[0] = '\0';
	break;

It looks like the "if (res < 0)" is supposed to be checking the return value
from the ioctl, but in fact is hidden by the "else".

Unless I'm misunderstanding the code, I think it should be something like:

	/* FGD MF *Must* wait for wink */
	if (!ast_strlen_zero(p->dop.dialstr)) {
		res = ioctl(p->subs[SUB_REAL].zfd, ZT_DIAL, &p->dop);
		if (res < 0) {
			ast_log(LOG_WARNING, "Unable to initiate dialing on trunk channel %d\n", p->channel);
			p->dop.dialstr[0] = '\0';
			return NULL;
		} else
			ast_log(LOG_DEBUG, "Sent deferred digit string: %s\n", p->dop.dialstr);
		p->dop.dialstr[0] = '\0';
	}
	break;

It is the same in 1.2 and trunk.

Cheers
Tony
-- 
Tony Mountifield
Work: tony at softins.co.uk - http://www.softins.co.uk
Play: tony at mountifield.org - http://tony.mountifield.org


More information about the asterisk-dev mailing list