FLTK logo

[master] 06e495f - Add NULL check to UNIX save_file() (#945)

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] 06e495f - Add NULL check to UNIX save_file() (#945) "Greg Ercolano" 10:17 Apr 04  
 
commit 06e495f26256a6d987f6d76cb291ba62fee85857
Author:     Greg Ercolano <erco@seriss.com>
AuthorDate: Thu Apr 4 10:03:35 2024 -0700
Commit:     Greg Ercolano <erco@seriss.com>
CommitDate: Thu Apr 4 10:03:35 2024 -0700

    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 fluid/ExternalCodeEditor_UNIX.cxx fluid/ExternalCodeEditor_UNIX.cxx
index a044160..4f0bea3 100644
--- fluid/ExternalCodeEditor_UNIX.cxx
+++ 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 fluid/ExternalCodeEditor_WIN32.cxx fluid/ExternalCodeEditor_WIN32.cxx
index 1afb0af..bb7d579 100644
--- fluid/ExternalCodeEditor_WIN32.cxx
+++ 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
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.