diff --git a/src/experimental/platform/file_dialog_zenity.cc b/src/experimental/platform/file_dialog_zenity.cc index 79edb7a4..21d51dc1 100644 --- a/src/experimental/platform/file_dialog_zenity.cc +++ b/src/experimental/platform/file_dialog_zenity.cc @@ -15,6 +15,7 @@ #include "experimental/platform/file_dialog.h" #include +#include #include #include #include @@ -45,8 +46,10 @@ static DialogResult RunZenity(std::vector& args) { if (ret == nullptr || ferror(output)) { return DialogResult{.status = DialogResult::kError}; } - if (buffer[kBufferSize - 1] == '\0') { - buffer[0] = '\0'; + // Zenity outputs a newline at the end of the buffer which we need to remove. + const int len = std::strlen(buffer); + if (len > 0) { + buffer[len - 1] = '\0'; } return DialogResult{.status = DialogResult::kAccepted, .path = std::string(buffer)};