ZhengweiZhu commented on code in PR #3158:
URL: https://github.com/apache/brpc/pull/3158#discussion_r2553838219


##########
src/bthread/types.h:
##########
@@ -118,6 +120,12 @@ typedef struct bthread_attr_t {
         return tmp;
     }
 #endif  // __cplusplus
+    void set_name(const char* val) {
+        if (val) {
+            strncpy(name, val, BTHREAD_NAME_MAX_LENGTH);
+            name[BTHREAD_NAME_MAX_LENGTH] = '\0';

Review Comment:
   > Actually there is a `bthread_attr_init` function. It is the right way to 
init a `bthread_attr_t` without using pre-defined macros like 'BTHREAD_ATTR_*'. 
This is a more extensible way.
   > In current way, some users may define `BTHREAD_ATTR_XXX` by themselves, 
but that code will be broken if we add new members to `bthread_attr_t`.
   
   Yes. As the bthread_attr_t struct is defined in C code style without 
defining ctor function, so when new members is added and user have defined its  
BTHREAD_ATTR_XXX by themselves and not used `bthread_attr_init`, the new added 
name filed will be uninitialized.  Shall we consider this scenario and how?



-- 
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