ddnet / ddnet

DDraceNetwork, a free cooperative platformer game
https://ddnet.org
Other
507 stars 383 forks source link

warning: 3 uninitialized fields at the end of the constructor call #8297

Closed ChillerDragon closed 4 days ago

ChillerDragon commented 2 weeks ago
/home/chiller/Desktop/git/ddnet/src/game/client/components/menus.h:710:46: warning: 3 uninitialized fields at the end of the constructor call [clang-analyzer-optin.cplusplus.UninitializedObject]                                                                                                                                                                                                                                                                                          
  710 |                         m_Slot(-1), m_Own(false) { m_aFilename[0] = 0; }                                                                                                                                                                                                                                                                                                                                                                                                            
      |                                                                   ^                                                                                                                                                                                                                                                                                                                                                                                                                 
/home/chiller/Desktop/git/ddnet/src/game/client/components/menus.h:703:8: note: uninitialized field 'this->m_Failed'                                                                                                                                                                                                                                                                                                                                                                        
  703 |                 bool m_Failed;                                                                                                                                                                                                                                                                                                                                                                                                                                                      
      |                      ^~~~~~~~                                                                                                                                                                                                                                                                                                                                                                                                                                                       
/home/chiller/Desktop/git/ddnet/src/game/client/components/menus.h:704:7: note: uninitialized field 'this->m_Time'                                                                                                                                                                                                                                                                                                                                                                          
  704 |                 int m_Time;                                                                                                                                                                                                                                                                                                                                                                                                                                                         
      |                     ^~~~~~                                                                                                                                                                                                                                                                                                                                                                                                                                                          
/home/chiller/Desktop/git/ddnet/src/game/client/components/menus.h:707:10: note: uninitialized field 'this->m_Date'                                                                                                                                                                                                                                                                         
  707 |                 time_t m_Date;                                                                                                                                                                                                                                                                                                                                                      
      |                        ^~~~~~                                                                                                                                                                                                                                                                                                                                                       
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:623:5: note: Assuming 'MsgType' is not equal to NETMSGTYPE_SV_KILLMSG                                                                                                                                                                                                                                                  
  623 |         if(MsgType == NETMSGTYPE_SV_KILLMSG)                                                                                                                                                                                                                                                                                                                                        
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                                                                                                                                                                                                                                                                                                         
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:623:2: note: Taking false branch                                                                                                                                                                                                                                                                                       
  623 |         if(MsgType == NETMSGTYPE_SV_KILLMSG)                                                                                                                                                                                                                                                                                                                                        
      |         ^                                                                                                                                                                                                                                                                                                                                                                           
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:634:10: note: Assuming 'MsgType' is not equal to NETMSGTYPE_SV_KILLMSGTEAM                                                                                                                                                                                                                                             
  634 |         else if(MsgType == NETMSGTYPE_SV_KILLMSGTEAM)                                                                                                                                                                                                                                                                                                                               
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                                                                                                                                                                                                                                                                                                
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:634:7: note: Taking false branch                                                                                                                                                                                                                                                                                       
  634 |         else if(MsgType == NETMSGTYPE_SV_KILLMSGTEAM)                                                                                                                                                                                                                                                                                                                               
      |              ^                                                                                                                                                                                                                                                                                                                                                                      
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:648:10: note: Assuming 'MsgType' is equal to NETMSGTYPE_SV_CHAT                                                                                                                                                                                                                                                        
  648 |         else if(MsgType == NETMSGTYPE_SV_CHAT)                                                                                                                                                                                                                                                                                                                                      
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                                                                                                                                                                                                                                                                                                       
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:648:7: note: Taking true branch                                                                                                                                                                                                                                                                                        
  648 |         else if(MsgType == NETMSGTYPE_SV_CHAT)                                                                                                                                                                                                                                                                                                                                      
      |              ^                                                                                                                                                                                                                                                                                                                                                                      
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:651:6: note: Assuming the condition is true                                                                                                                                                                                                                                                                            
  651 |                 if(pMsg->m_ClientId == -1 && m_Recording)                                                                                                                                                                                                                                                                                                                           
      |                    ^~~~~~~~~~~~~~~~~~~~~~                                                                                                                                                                                                                                                                                                                                           
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:651:6: note: Left side of '&&' is true                                                                                                                                                                                                                                                                                 
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:651:32: note: Assuming field 'm_Recording' is true                                                                                                                                                                                                                                                                     
  651 |                 if(pMsg->m_ClientId == -1 && m_Recording)                                                                                                                                                                                                                                                                                                                           
      |                                              ^~~~~~~~~~~                                                                                                                                                                                                                                                                                                                            
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:651:3: note: Taking true branch                                                                                                                                                                                                                                                                                        
  651 |                 if(pMsg->m_ClientId == -1 && m_Recording)                                                                                                                                                                                                                                                                                                                           
      |                 ^                                                                                                                                                                                                                                                                                                                                                                   
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:655:7: note: Assuming 'Time' is > 0                                                                                                                                                                                                                                                                                    
  655 |                         if(Time > 0 && m_pClient->m_Snap.m_LocalClientId >= 0 && str_comp(aName, m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientId].m_aName) == 0)                                                                                                                                                                                                            
      |                            ^~~~~~~~                                                                                                                                                                                                                                                                                                                                                 
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:655:7: note: Left side of '&&' is true                                                                                                                                                                                                                                                                                 
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:655:19: note: Assuming field 'm_LocalClientId' is >= 0                                                                                                                                                                                                                                                                 
  655 |                         if(Time > 0 && m_pClient->m_Snap.m_LocalClientId >= 0 && str_comp(aName, m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientId].m_aName) == 0)                                                                                                                                                                                                            
      |                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                                                                                                                                                                                                                                                                       
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:655:7: note: Left side of '&&' is true                                                                                                                                                                                                                                                                                 
  655 |                         if(Time > 0 && m_pClient->m_Snap.m_LocalClientId >= 0 && str_comp(aName, m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientId].m_aName) == 0)                                                                                                                                                                                                            
      |                            ^                                                           
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:655:61: note: Assuming the condition is true                                                                              
  655 |                         if(Time > 0 && m_pClient->m_Snap.m_LocalClientId >= 0 && str_comp(aName, m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientId].m_aName) == 0)
      |                                                                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:655:4: note: Taking true branch                                                                                           
  655 |                         if(Time > 0 && m_pClient->m_Snap.m_LocalClientId >= 0 && str_comp(aName, m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientId].m_aName) == 0)
      |                         ^                                                              
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:657:5: note: Calling 'CGhost::StopRecord'                                                                                 
  657 |                                 StopRecord(Time);                                                              
      |                                 ^~~~~~~~~~~~~~~~                                                               
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:432:5: note: Assuming 'RecordingToFile' is false                                                                                                                          
  432 |         if(RecordingToFile)                        
      |            ^~~~~~~~~~~~~~~                         
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:432:2: note: Taking false branch                  
  432 |         if(RecordingToFile)                        
      |         ^                                          
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:436:5: note: 'Time' is > 0                        
  436 |         if(Time > 0 && (!pOwnGhost || Time < pOwnGhost->m_Time || !g_Config.m_ClRaceGhostSaveBest))                                                                                                                                    
      |            ^~~~                                    
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:436:5: note: Left side of '&&' is true                                                                                                                                    
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:436:18: note: Assuming 'pOwnGhost' is null                                                                                                                               
  436 |         if(Time > 0 && (!pOwnGhost || Time < pOwnGhost->m_Time || !g_Config.m_ClRaceGhostSaveBest))                                                                                                                                   
      |                         ^~~~~~~~~~                                                                             
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:436:29: note: Left side of '||' is true                                                                                                                                  
  436 |         if(Time > 0 && (!pOwnGhost || Time < pOwnGhost->m_Time || !g_Config.m_ClRaceGhostSaveBest))                                                                                                                                   
      |                                    ^                                                                           
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:440:6: note: Assuming the condition is false                                                                                                                             
  440 |                 if(Slot != -1 && (!pOwnGhost || Time < pOwnGhost->m_Time))                                     
      |                    ^~~~~~~~~~                                                                                  
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:440:17: note: Left side of '&&' is false                                                                                                                                 
  440 |                 if(Slot != -1 && (!pOwnGhost || Time < pOwnGhost->m_Time))                                     
      |                               ^                                                                                
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:443:6: note: 'pOwnGhost' is null                  
  443 |                 if(pOwnGhost && pOwnGhost->Active() && Time < pOwnGhost->m_Time)                               
      |                    ^~~~~~~~~                                                                                   
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:443:16: note: Left side of '&&' is false                                                                                                                                 
  443 |                 if(pOwnGhost && pOwnGhost->Active() && Time < pOwnGhost->m_Time)                               
      |                              ^                                                                                 
/home/chiller/Desktop/git/ddnet/src/game/client/components/ghost.cpp:447:22: note: Calling default constructor for 'CGhostItem'                                                                                                               
  447 |                 CMenus::CGhostItem Item;                                                                       
      |                                    ^~~~                                                                        
/home/chiller/Desktop/git/ddnet/src/game/client/components/menus.h:710:46: note: 3 uninitialized fields at the end of the constructor call                                                                                                    
  710 |                         m_Slot(-1), m_Own(false) { m_aFilename[0] = 0; }                                       
      |  
heinrich5991 commented 2 weeks ago

Toolchain version? Is this a false positive?

ChillerDragon commented 2 weeks ago

Toolchain version?

LLVM (http://llvm.org/):
  LLVM version 19.0.0git
  Optimized build.

Is this a false positive?

I do not know. I somehow trust clang but haven't checked. Do you think it is a false positive? Then we can close it.

heinrich5991 commented 2 weeks ago

I somehow trust clang but haven't checked.

Please check before creating an issue.

ChillerDragon commented 2 weeks ago

Please check before creating an issue.

I create issues to check later. Or should I create those issues in my fork instead?

ChillerDragon commented 1 week ago

Reopend by https://github.com/ddnet/ddnet/pull/8327

heinrich5991 commented 4 days ago

Is this a lint we want to enable? What are the advantages and disadvantages?

Robyt3 commented 4 days ago

I think checks for uninitialized memory are generally useful, some weird UI bug have been caused by uninitialized memory in the past and this can be hard to debug.

In this case it seems like a false-positive though. AFAICT the check assumes that the CMenus::CGhostItem members m_aPlayer, m_Failed and m_Date are uninitialized, but m_aPlayer is initialized immediately after constructing the object and the other two variable are initialized in UpdateOwnGhost.

However, the check in question, clang-analyzer-optin.cplusplus.UninitializedObject, is already suppressed globally

https://github.com/ddnet/ddnet/blob/03b13cb9f51a343f61aac89c18bc5f7814a5e253/.clang-tidy#L3-L4

so it seems like we already decided to ignore this check at some point.

ChillerDragon commented 4 days ago

Okay I see. Unwanted lint and false positive. I would consider this issue solved.