Skip to content

Commit 6b03720

Browse files
authored
sapi/cli: setting process name little optimisation. (#14767)
1 parent 7575905 commit 6b03720

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

sapi/cli/ps_title.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* The following code is adopted from the PostgreSQL's ps_status(.h/.c).
2929
*/
3030

31+
#include <php.h>
3132
#ifdef PHP_WIN32
3233
#include "config.w32.h"
3334
#include <windows.h>
@@ -342,9 +343,8 @@ int set_ps_title(const char* title)
342343
if (rc != PS_TITLE_SUCCESS)
343344
return rc;
344345

345-
strncpy(ps_buffer, title, ps_buffer_size);
346-
ps_buffer[ps_buffer_size - 1] = '\0';
347-
ps_buffer_cur_len = strlen(ps_buffer);
346+
size_t title_len = strlcpy(ps_buffer, title, ps_buffer_size);
347+
ps_buffer_cur_len = (title_len >= ps_buffer_size) ? ps_buffer_size - 1 : title_len;
348348

349349
#ifdef PS_USE_SETPROCTITLE
350350
setproctitle("%s", ps_buffer);

0 commit comments

Comments
 (0)