unbreak profiler_unittest when linking statically

When linking statically we may end up calling ProfilerGetCurrentState
earlier than profiler is initialized. And we segfaulted on that early
call. Lets make us handle this case gracefully.
This commit is contained in:
Aliaksei Kandratsenka 2024-09-27 22:20:08 -04:00
parent f0bab33d27
commit b128b1557e
1 changed files with 1 additions and 1 deletions

View File

@ -210,7 +210,7 @@ void ProfileData::GetCurrentState(State* state) const {
state->start_time = start_time_;
state->samples_gathered = count_;
int buf_size = sizeof(state->profile_name);
strncpy(state->profile_name, fname_, buf_size);
strncpy(state->profile_name, fname_ ? fname_ : "", buf_size);
state->profile_name[buf_size-1] = '\0';
} else {
state->enabled = false;