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
This commit is contained in:
Bill Meier 2011-01-30 21:56:05 +00:00
parent 84bc28bd6a
commit 164b0e4a9d
1 changed files with 6 additions and 4 deletions

View File

@ -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) {