diff options
author | Bill Meier <wmeier@newsguy.com> | 2011-01-30 21:56:05 +0000 |
---|---|---|
committer | Bill Meier <wmeier@newsguy.com> | 2011-01-30 21:56:05 +0000 |
commit | 164b0e4a9d064228672bd4cbf55270746653816f (patch) | |
tree | 00502ef9b9f900b3bca68153c4095b82cf8a5392 /tap-megaco-common.c | |
parent | 84bc28bd6abc416b3ef2762157d957ee58bb8791 (diff) |
When searching a list, validate pointer before (not after) trying to use it.
In this particular case, the code logic may ensure that
the search thru the list never hits the end of the list so that a
crash because of an attempt to deref a NULL pointer never happens.
Issue found via msvc level 4 warning "code not reachable".
svn path=/trunk/; revision=35706
Diffstat (limited to 'tap-megaco-common.c')
-rw-r--r-- | tap-megaco-common.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/tap-megaco-common.c b/tap-megaco-common.c index 93e6a711f4..03ffeb7660 100644 --- a/tap-megaco-common.c +++ b/tap-megaco-common.c @@ -57,8 +57,9 @@ megacostat_is_duplicate_reply(const gcp_cmd_t* cmd) { gcp_cmd_msg_t *cmd_msg; /* cycle through commands to find same command in the transaction */ - for (cmd_msg = cmd->trx->cmds; cmd_msg->cmd->msg->framenum != cmd->msg->framenum && - cmd_msg != NULL; cmd_msg = cmd_msg->next) { + for (cmd_msg = cmd->trx->cmds; + (cmd_msg != NULL) && (cmd_msg->cmd->msg->framenum != cmd->msg->framenum); + cmd_msg = cmd_msg->next) { if (cmd_msg->cmd->type == cmd->type) return TRUE; } @@ -83,8 +84,9 @@ megacostat_had_request(const gcp_cmd_t* cmd) { gcp_cmd_msg_t *cmd_msg; /* cycle through commands to find a request in the transaction */ - for (cmd_msg = cmd->trx->cmds; cmd_msg->cmd->msg->framenum != cmd->msg->framenum && - cmd_msg != NULL; cmd_msg = cmd_msg->next) { + for (cmd_msg = cmd->trx->cmds; + (cmd_msg != NULL) && (cmd_msg->cmd->msg->framenum != cmd->msg->framenum); + cmd_msg = cmd_msg->next) { switch (cmd_msg->cmd->type) { |