diff -u -r nano-boo/src/files.c nano-die/src/files.c --- nano-boo/src/files.c 2004-08-05 17:02:49.000000000 -0400 +++ nano-die/src/files.c 2004-08-05 17:04:28.000000000 -0400 @@ -394,19 +394,22 @@ } /* This function will return the name of the first available extension - * of a filename (starting with the filename, then filename.1, etc). - * Memory is allocated for the return value. If no writable extension - * exists, we return "". */ + * of a filename (starting with the filename.save, then filename.save.1, + * etc). Memory is allocated for the return value. If no writable + * extension exists, we return "". */ char *get_next_filename(const char *name) { int i = 0; - char *buf = NULL; - struct stat fs; + char *buf; + size_t namelen = strlen(name); - buf = charalloc(strlen(name) + num_of_digits(INT_MAX) + 2); + buf = charalloc(namelen + num_of_digits(INT_MAX) + 7); strcpy(buf, name); + strcpy(buf + namelen, ".save"); + namelen += 5; while (TRUE) { + struct stat fs; if (stat(buf, &fs) == -1) return buf; @@ -414,8 +417,7 @@ break; i++; - strcpy(buf, name); - sprintf(&buf[strlen(name)], ".%d", i); + sprintf(buf + namelen, ".%d", i); } /* We get here only if there is no possible save file. */ diff -u -r nano-boo/src/nano.c nano-die/src/nano.c --- nano-boo/src/nano.c 2004-08-05 17:02:49.000000000 -0400 +++ nano-die/src/nano.c 2004-08-05 17:04:11.000000000 -0400 @@ -170,15 +170,9 @@ /* If we can't save, we have REAL bad problems, but we might as well TRY. */ if (die_filename[0] == '\0') - ret = get_next_filename("nano.save"); - else { - char *buf = charalloc(strlen(die_filename) + 6); + die_filename = "nano"; - strcpy(buf, die_filename); - strcat(buf, ".save"); - ret = get_next_filename(buf); - free(buf); - } + ret = get_next_filename(die_filename); if (ret[0] != '\0') succeeded = -1 != write_file(ret, TRUE, FALSE, TRUE);