Samunroyu commented on code in PR #2328:
URL: 
https://github.com/apache/incubator-pegasus/pull/2328#discussion_r3418305342


##########
src/rpc/rpc_host_port.h:
##########
@@ -215,15 +215,18 @@ class TProtocol;
 // Head insert 'hp' and its DNS resolved rpc_address to the optional vector 
'hp_<field>' and vector
 // '<field>' of 'obj'. The types of the fields are std::vector<rpc_address> and
 // std::vector<host_port>, respectively.
-#define HEAD_INSERT_IP_AND_HOST_PORT_BY_DNS(obj, field, hp)                    
                    \
+#define HEAD_INSERT_IP_AND_HOST_PORT_BY_DNS(obj, field, hp, target)            
                    \
     do {                                                                       
                    \
         auto &_obj = (obj);                                                    
                    \
         const auto &_hp = (hp);                                                
                    \
+        auto &_target = (target);                                              
                    \
         _obj.field.insert(_obj.field.begin(), _hp.resolve());                  
                    \
         if (!_obj.__isset.hp_##field) {                                        
                    \
             _obj.__set_hp_##field({_hp});                                      
                    \
+            _target.emplace_back(_hp);                                         
                    \
         } else {                                                               
                    \
             _obj.hp_##field.insert(_obj.hp_##field.begin(), _hp);              
                    \
+            _target = _obj.hp_##field;                                         
                    \
         }                                                                      
                    \
         DCHECK_EQ(_obj.field.size(), _obj.hp_##field.size());                  
                    \
     } while (0)

Review Comment:
   > The macro updates `_target` inconsistently: in the `!__isset` branch it 
appends (`emplace_back`) whereas in the `else` branch it overwrites (`_target = 
_obj.hp_##field`). If the caller passes a non-empty `_target` (or reuses a 
buffer), this can diverge from `_obj.hp_##field` and/or duplicate entries. Make 
`_target` deterministic by assigning it from `_obj.hp_##field` in both branches 
(or remove the `target` param and let callers call `GET_HOST_PORTS` after 
mutation).
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to