From 34add7bb328307fbe8f729b2e4c86af04d2b1a74 Mon Sep 17 00:00:00 2001 From: Haroon Qureshi Date: Tue, 3 Feb 2026 06:14:07 -0800 Subject: [PATCH] Removing trailing newline in zenity file dialogs. PiperOrigin-RevId: 864842389 Change-Id: Ie4cc61a91732fcde0ef2c7eba927aede217b2e6d --- src/experimental/platform/file_dialog_zenity.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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)};