Add NULL check to UNIX save_file() (#945)

This commit is contained in:
Greg Ercolano 2024-04-04 10:03:35 -07:00
parent f779097c96
commit 06e495f262
2 changed files with 5 additions and 1 deletions

View File

@ -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),

View File

@ -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