@@ -266,7 +266,7 @@ void FileWidget::fileOpen(EditorWidget *_saveEditorAs) {
266266//
267267void FileWidget::openPath (const char *newPath, StringList *recentPaths) {
268268 if (newPath && access (newPath, R_OK) == 0 ) {
269- strcpy (_path, newPath);
269+ strlcpy (_path, newPath, PATH_MAX );
270270 } else {
271271 getcwd (_path, sizeof (_path));
272272 }
@@ -285,7 +285,7 @@ void FileWidget::openPath(const char *newPath, StringList *recentPaths) {
285285void FileWidget::changeDir (const char *target) {
286286 char newPath[PATH_MAX + 1 ];
287287
288- strcpy (newPath, _path);
288+ strlcpy (newPath, _path, PATH_MAX );
289289
290290 // file browser window
291291 if (strcmp (target, " .." ) == 0 ) {
@@ -299,9 +299,9 @@ void FileWidget::changeDir(const char *target) {
299299 } else {
300300 // go down a level
301301 if (newPath[strlen (newPath) - 1 ] != ' /' ) {
302- strcat (newPath, " /" );
302+ strlcat (newPath, " /" , PATH_MAX );
303303 }
304- strcat (newPath, target);
304+ strlcat (newPath, target, PATH_MAX );
305305 }
306306 setDir (newPath);
307307}
@@ -311,7 +311,7 @@ void FileWidget::changeDir(const char *target) {
311311//
312312void FileWidget::setDir (const char *target) {
313313 if (chdir (target) == 0 ) {
314- strcpy (_path, target);
314+ strlcpy (_path, target, PATH_MAX );
315315 displayPath ();
316316 } else {
317317 fl_message (" Invalid path '%s'" , target);
@@ -365,10 +365,10 @@ void FileWidget::displayPath() {
365365 if (_saveEditorAs) {
366366 const char *path = _saveEditorAs->getFilename ();
367367 const char *slash = strrchr (path, ' /' );
368- html.append (" <b>Save " ).append (slash ? slash + 1 : path).append (" as:<br>" )
368+ html.append (" <b>Save " ).append (slash ? slash + 1 : path).append (" as:<font size=3>< br>" )
369369 .append (" <input size=220 type=text value='" ).append (slash ? slash + 1 : path)
370370 .append (" ' name=saveas> <input type=button onclick='" )
371- .append (CMD_SAVE_AS).append (" ' value='Save As'><br><br >" );
371+ .append (CMD_SAVE_AS).append (" ' value='Save As'><br><font size=1 >" );
372372 }
373373
374374 _recentPaths->sort (stringCompare);
@@ -433,7 +433,7 @@ void FileWidget::enterPath() {
433433 const char *newPath = fl_input (" Enter path:" , _path);
434434 if (newPath != 0 ) {
435435 if (chdir (newPath) == 0 ) {
436- strcpy (_path, newPath);
436+ strlcpy (_path, newPath, PATH_MAX );
437437 displayPath ();
438438 } else {
439439 fl_message (" Invalid path '%s'" , newPath);
@@ -497,23 +497,26 @@ void FileWidget::saveAs() {
497497 // substitute ~ for $HOME contents
498498 const char *home = dev_getenv (" HOME" );
499499 if (home) {
500- strcpy (savepath, home);
500+ strlcpy (savepath, home, PATH_MAX );
501501 } else {
502502 savepath[0 ] = 0 ;
503503 }
504- strcat (savepath, enteredPath + 1 );
504+ strlcat (savepath, enteredPath + 1 , PATH_MAX );
505505 } else if (enteredPath[0 ] == ' /' || enteredPath[1 ] == ' :' ) {
506506 // absolute path given
507- strcpy (savepath, enteredPath);
507+ strlcpy (savepath, enteredPath, PATH_MAX );
508508 } else {
509- strcpy (savepath, _path);
510- strcat (savepath, " /" );
511- strcat (savepath, enteredPath);
509+ strlcpy (savepath, _path, PATH_MAX);
510+ strlcat (savepath, " /" , PATH_MAX);
511+ strlcat (savepath, enteredPath, PATH_MAX);
512+ }
513+ if (strcasecmp (savepath + strlen (savepath) - 4 , " .bas" ) != 0 ) {
514+ strlcat (savepath, " .bas" , PATH_MAX);
512515 }
513516 const char *msg = " %s\n\n File already exists.\n Do you want to replace it?" ;
514517 if (access (savepath, 0 ) != 0 || fl_choice (msg, " Yes" , " No" , 0 , savepath) == 0 ) {
515- _saveEditorAs->doSaveFile (savepath);
516- }
518+ _saveEditorAs->doSaveFile (savepath, true );
519+ }
517520 }
518521 }
519522}
0 commit comments