From 0b96f88966f99b301d92e55ce48b8f2027d8d1b0 Mon Sep 17 00:00:00 2001 From: Ivica Ico Bukvic <ico@vt.edu> Date: Sun, 31 Aug 2014 23:01:50 -0400 Subject: [PATCH] *fixed segfault at start-up due to faulty allocation of the string length for checking for unique instance of pd-l2ork *made unique check in pd.tk more robust in respect to relative paths and multiple files by making sure that the script always goes back to the original directory from which it was invoked, so as to ensure that the path (if relative) is valid --- pd/src/pd.tk | 6 ++++-- pd/src/s_main.c | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pd/src/pd.tk b/pd/src/pd.tk index a71b5b16f..4a81db78f 100644 --- a/pd/src/pd.tk +++ b/pd/src/pd.tk @@ -8461,14 +8461,16 @@ proc pdtk_open_files_via_unique {filenames} { proc pdtk_check_unique {unique filenames} { #puts stderr "pdtk_check_unique $unique $filenames" global appname + set startup_dir [pwd] if { $unique == 0 } { foreach file $filenames { - #puts stderr $file - cd [file dirname $file] + #puts stderr "$file [file dirname $file] $startup_dir" + catch {cd [file dirname $file]} set dir [pwd] set name [file tail $file] #puts stderr "********DIR:$dir FILE:$name COMBINED:[file join $dir $name]" lappend final_filenames [file join $dir $name] + cd $startup_dir } #puts stderr "send pd-l2ork pdtk_open_files_via_unique $final_filenames" set outcome [catch {send pd-l2ork pdtk_open_files_via_unique \{$final_filenames\}}] diff --git a/pd/src/s_main.c b/pd/src/s_main.c index 6ef5121d6..85eaf34a7 100644 --- a/pd/src/s_main.c +++ b/pd/src/s_main.c @@ -309,7 +309,11 @@ int sys_main(int argc, char **argv) int length = 0; t_namelist *nl; for (nl = sys_openlist; nl; nl = nl->nl_next) - length = length + strlen(nl->nl_string) + 1; + { + // for starting and ending quotes plus a space or null terminating + // character, we add 3 additional characters per entry + length = length + strlen(nl->nl_string) + 3; + } if((filenames = malloc(length)) != NULL) { filenames[0] = '\0'; // ensures the memory is an empty string @@ -321,7 +325,7 @@ int sys_main(int argc, char **argv) strcat(filenames,nl->nl_string); if (nl->nl_next) strcat(filenames,"\" \""); - else strcat(filenames,"\""); + else strcat(filenames,"\"\0"); // ensures proper termination } } //fprintf(stderr,"final list: <%s>\n", filenames); -- GitLab