Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 609
  • Last Modified:

help debugging

I have been asked to debug a piece of code. I am having a problem understanding part of it. Here is the code:

if ( update & No_UpdateType == No_UpdateType )
     
     {    
          return false;
         
     }  
     
if ( update & Private_UpdateType == Private_UpdateType )
         
     {    
          for ( i = 0; i < m_numEvents; ++i )      
          {        
               if ( m_eventFilter[i] == key )
                   
               {          
                    retval = true;  
               }
     
               else
               {        
                    retval = false;        
               }      
     }
         
          if ( retval )      
          {
               SendPrivateNetworkEvent( buffer, key, val );  
          }  
     }  



What I don't understand are the conditions in the two main if statements:

if ( update & No_UpdateType == No_UpdateType )
and
if ( update & Private_UpdateType == Private_UpdateType )

Should there be two ampersands? Is update a class? I don't know. In case that isn't enough enough information, below is the entire code segment. I would appreciate any help.

boolEntity::SetInt( INT_STAT key, int val, UpdateType update )
{  
  m_Qualities->SetInt( key, val );  //I am also a litle confused with this line
  int i;  
  bool retval;
  byte* buffer = new byte[ 256 ];

  if ( update & No_UpdateType == No_UpdateType )
    {    return false;  }  

  if ( update & Private_UpdateType == Private_UpdateType )
  {  
    for ( i = 0; i < m_numEvents; ++i )      
    {    
      if ( m_eventFilter[i] == key )
         {retval = true; }
      else
         {retval = false;}      
    }    

    if ( retval )
    {
      SendPrivateNetworkEvent( buffer, key, val );    
     }  
   }  

  if ( update & Public_UpdateType == Public_UpdateType )
  {      
    for ( i = 0; i < m_numEvents; ++i )
    {
        if ( m_eventFilter[i] == key )
          { retval = true; }
        else
          { retval = false; }      
     }    
   
    if ( retval )
    {    
       SendPublicNetworkEvent( buffer, key, val );  
    }  
  }
  delete buffer;  
  return retval;
}
0
sgugi
Asked:
sgugi
  • 5
  • 3
1 Solution
 
jkrCommented:

>>What I don't understand are the conditions in the two main if statements:

>>if ( update & No_UpdateType == No_UpdateType )

"update & No_UpdateType" checks whether a certain bit is set in the variable "update" ('&' is the bitwise AND operator). Actually, both statements are redundant,

if ( update & No_UpdateType )

would be enough.

0
 
sgugiAuthor Commented:
Thank you jkr, that helped.

Looking at the code again, I realized I had another couple of questions:

What exactly is the point of the buffer in this code segment?
and
What is the purpose of this line?
m_Qualities->SetInt( key, val )  
0
 
jkrCommented:
>>What exactly is the point of the buffer in this code segment?

To be hinest - none. It is never being initialized, and unless it is some sort of of a receive buffer (which its usage with 'SendPublicNetworkEvent()' does not suggest), it seems to be bogus.

>>m_Qualities->SetInt( key, val )  

It calls a method of an object via a pointer to that object.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
sgugiAuthor Commented:
Thanks again jkr. Do you suggest getting rid of the buffer entirely?
0
 
jkrCommented:
>>Do you suggest getting rid of the buffer entirely?

Only if 'SendPublicNetworkEvent()' can cope with a NULL pointer as the 1st argument.
0
 
jkrCommented:
Anything else you need to know?
0
 
sgugiAuthor Commented:
I think I'm all set now. Thanks for your help!
0
 
jkrCommented:
So, could we close this Q then? .o)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now