From 06e495f26256a6d987f6d76cb291ba62fee85857 Mon Sep 17 00:00:00 2001 From: Greg Ercolano Date: Thu, 4 Apr 2024 10:03:35 -0700 Subject: [PATCH] Add NULL check to UNIX save_file() (#945) --- fluid/ExternalCodeEditor_UNIX.cxx | 2 ++ fluid/ExternalCodeEditor_WIN32.cxx | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/fluid/ExternalCodeEditor_UNIX.cxx b/fluid/ExternalCodeEditor_UNIX.cxx index a04416034..4f0bea3f9 100644 --- a/fluid/ExternalCodeEditor_UNIX.cxx +++ b/fluid/ExternalCodeEditor_UNIX.cxx @@ -312,6 +312,7 @@ const char* ExternalCodeEditor::tmp_filename() { \return -1 on error (posts dialog with reason) */ static int save_file(const char *filename, const char *code) { + if ( code == 0 ) code = ""; // NULL? write an empty file int fd = open(filename, O_WRONLY|O_CREAT, 0666); if ( fd == -1 ) { fl_alert("ERROR: open() '%s': %s", filename, strerror(errno)); @@ -460,6 +461,7 @@ int ExternalCodeEditor::reap_editor(pid_t *pid_reaped) { Open external editor using 'editor_cmd' to edit 'code'. 'code' contains multiline code to be edited as a temp file. + 'code' can be NULL -- edits an empty file if so. \return 0 if succeeds \return -1 if can't open editor (already open, etc), diff --git a/fluid/ExternalCodeEditor_WIN32.cxx b/fluid/ExternalCodeEditor_WIN32.cxx index 1afb0afff..bb7d5791a 100644 --- a/fluid/ExternalCodeEditor_WIN32.cxx +++ b/fluid/ExternalCodeEditor_WIN32.cxx @@ -544,8 +544,10 @@ int ExternalCodeEditor::reap_editor(DWORD *pid_reaped) { return -1; // any other return unexpected } -// [Public] Open external editor using 'editor_cmd' to edit 'code' +// [Public] Open external editor using 'editor_cmd' to edit 'code'. +// // 'code' contains multiline code to be edited as a temp file. +// 'code' can be NULL -- edits an empty file if so. // // Returns: // 0 if succeeds