Regal2XY commented on code in PR #3158:
URL: https://github.com/apache/brpc/pull/3158#discussion_r2548364143
##########
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:
For static constants like BTHREAD_ATTR_NORMAL, the name field is initialized
with {0}, which sets all elements of the array (including the last one) to
zero. This means the name is already fully null-initialized, and no further
action is needed to ensure it is null-terminated as we only strncpy
BTHREAD_NAME_MAX_LENGTH (which is less than array size) elements. This line is
actually not needed but kept here just for coding style.
The current implementation handles well whether the length of name execeeds
BTHREAD_NAME_MAX_LENGTH or not.
--
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]