mirror of
https://github.com/Interlisp/maiko.git
synced 2026-02-27 17:12:42 +00:00
Replace sprintf() with snprintf()
This commit is contained in:
48
src/dir.c
48
src/dir.c
@@ -20,7 +20,7 @@
|
||||
#define alarm(x) 1
|
||||
#endif /* DOS */
|
||||
#include <errno.h> // for errno, EINTR, ENOENT
|
||||
#include <stdio.h> // for NULL, sprintf, size_t
|
||||
#include <stdio.h> // for NULL, snprintf, size_t
|
||||
#include <stdlib.h> // for calloc, free, strtoul, malloc, qsort
|
||||
#include <string.h> // for strcpy, strcmp, strlen, strrchr, strcat
|
||||
#include <sys/stat.h> // for stat, S_ISDIR, st_atime, st_mtime
|
||||
@@ -441,11 +441,11 @@ static int enum_dsk_prop(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
||||
nextp->next = prevp;
|
||||
if (isslash) {
|
||||
if (drive)
|
||||
sprintf(namebuf, "%c:\\%s", drive, dirp.name);
|
||||
snprintf(namebuf, sizeof(namebuf), "%c:\\%s", drive, dirp.name);
|
||||
else
|
||||
sprintf(namebuf, "\\%s", dirp.name);
|
||||
snprintf(namebuf, sizeof(namebuf), "\\%s", dirp.name);
|
||||
} else
|
||||
sprintf(namebuf, "%s\\%s", dir, dirp.name);
|
||||
snprintf(namebuf, sizeof(namebuf), "%s\\%s", dir, dirp.name);
|
||||
|
||||
TIMEOUT(rval = stat(namebuf, &sbuf));
|
||||
if (rval == -1 && errno != ENOENT) {
|
||||
@@ -511,11 +511,11 @@ static int enum_dsk_prop(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
||||
|
||||
if (isslash) {
|
||||
if (drive)
|
||||
sprintf(namebuf, "%c:\\%s", drive, old);
|
||||
snprintf(namebuf, sizeof(namebuf), "%c:\\%s", drive, old);
|
||||
else
|
||||
sprintf(namebuf, "\\%s", old);
|
||||
snprintf(namebuf, sizeof(namebuf), "\\%s", old);
|
||||
} else
|
||||
sprintf(namebuf, "%s\\%s", dir, old);
|
||||
snprintf(namebuf, sizeof(namebuf), "%s\\%s", dir, old);
|
||||
TIMEOUT(rval = stat(namebuf, &sbuf));
|
||||
|
||||
if (rval == -1) continue;
|
||||
@@ -524,7 +524,7 @@ static int enum_dsk_prop(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
||||
newp->next = prevp;
|
||||
/* All other types than directory. */
|
||||
newp->dirp = 0;
|
||||
sprintf(namebuf, "%s.~00~", nextp->no_ver_name);
|
||||
snprintf(namebuf, sizeof(namebuf), "%s.~00~", nextp->no_ver_name);
|
||||
quote_fname(namebuf);
|
||||
len = strlen(namebuf);
|
||||
strcpy(newp->lname, namebuf);
|
||||
@@ -582,7 +582,7 @@ static int enum_dsk_prop(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
||||
return (-1);
|
||||
}
|
||||
nextp->next = prevp;
|
||||
sprintf(namebuf, "%s/%s", dir, dp->d_name);
|
||||
snprintf(namebuf, sizeof(namebuf), "%s/%s", dir, dp->d_name);
|
||||
TIMEOUT(rval = stat(namebuf, &sbuf));
|
||||
if (rval == -1 && errno != ENOENT) {
|
||||
/*
|
||||
@@ -720,11 +720,11 @@ static int enum_dsk(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
||||
nextp->next = prevp;
|
||||
if (isslash) {
|
||||
if (drive)
|
||||
sprintf(namebuf, "%c:\\%s", drive, dirp.name);
|
||||
snprintf(namebuf, sizeof(namebuf), "%c:\\%s", drive, dirp.name);
|
||||
else
|
||||
sprintf(namebuf, "\\%s", dirp.name);
|
||||
snprintf(namebuf, sizeof(namebuf), "\\%s", dirp.name);
|
||||
} else
|
||||
sprintf(namebuf, "%s\\%s", dir, dirp.name);
|
||||
snprintf(namebuf, sizeof(namebuf), "%s\\%s", dir, dirp.name);
|
||||
TIMEOUT(rval = stat(namebuf, &sbuf));
|
||||
if (rval == -1 && errno != ENOENT) {
|
||||
/*
|
||||
@@ -776,11 +776,11 @@ static int enum_dsk(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
||||
|
||||
if (isslash) {
|
||||
if (drive)
|
||||
sprintf(namebuf, "%c:\\%s", drive, old);
|
||||
snprintf(namebuf, sizeof(namebuf), "%c:\\%s", drive, old);
|
||||
else
|
||||
sprintf(namebuf, "\\%s", old);
|
||||
snprintf(namebuf, sizeof(namebuf), "\\%s", old);
|
||||
} else
|
||||
sprintf(namebuf, "%s\\%s", dir, old);
|
||||
snprintf(namebuf, sizeof(namebuf), "%s\\%s", dir, old);
|
||||
TIMEOUT(rval = stat(namebuf, &sbuf));
|
||||
|
||||
if (rval == -1) continue;
|
||||
@@ -789,7 +789,7 @@ static int enum_dsk(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
||||
newp->next = prevp;
|
||||
/* All other types than directory. */
|
||||
newp->dirp = 0;
|
||||
sprintf(namebuf, "%s.~00~", nextp->no_ver_name);
|
||||
snprintf(namebuf, sizeof(namebuf), "%s.~00~", nextp->no_ver_name);
|
||||
quote_fname(namebuf);
|
||||
len = strlen(namebuf);
|
||||
strcpy(newp->lname, namebuf);
|
||||
@@ -845,7 +845,7 @@ static int enum_dsk(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
||||
return (-1);
|
||||
}
|
||||
nextp->next = prevp;
|
||||
sprintf(namebuf, "%s/%s", dir, dp->d_name);
|
||||
snprintf(namebuf, sizeof(namebuf), "%s/%s", dir, dp->d_name);
|
||||
TIMEOUT(rval = stat(namebuf, &sbuf));
|
||||
if (rval == -1 && errno != ENOENT) {
|
||||
/*
|
||||
@@ -949,7 +949,7 @@ static int enum_ufs_prop(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
||||
return (-1);
|
||||
}
|
||||
nextp->next = prevp;
|
||||
sprintf(namebuf, "%s\\%s", dir, dirp.name);
|
||||
snprintf(namebuf, sizeof(namebuf), "%s\\%s", dir, dirp.name);
|
||||
TIMEOUT(rval = stat(namebuf, &sbuf));
|
||||
if (rval == -1 && errno != ENOENT) {
|
||||
/*
|
||||
@@ -1040,7 +1040,7 @@ static int enum_ufs_prop(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
||||
return (-1);
|
||||
}
|
||||
nextp->next = prevp;
|
||||
sprintf(namebuf, "%s/%s", dir, dp->d_name);
|
||||
snprintf(namebuf, sizeof(namebuf), "%s/%s", dir, dp->d_name);
|
||||
TIMEOUT(rval = stat(namebuf, &sbuf));
|
||||
if (rval == -1 && errno != ENOENT) {
|
||||
/*
|
||||
@@ -1148,7 +1148,7 @@ static int enum_ufs(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
||||
return (-1);
|
||||
}
|
||||
nextp->next = prevp;
|
||||
sprintf(namebuf, "%s\\%s", dir, dirp.name);
|
||||
snprintf(namebuf, sizeof(namebuf), "%s\\%s", dir, dirp.name);
|
||||
TIMEOUT(rval = stat(namebuf, &sbuf));
|
||||
if (rval == -1 && errno != ENOENT) {
|
||||
/*
|
||||
@@ -1223,7 +1223,7 @@ static int enum_ufs(char *dir, char *name, char *ver, FINFO **finfo_buf)
|
||||
return (-1);
|
||||
}
|
||||
nextp->next = prevp;
|
||||
sprintf(namebuf, "%s/%s", dir, dp->d_name);
|
||||
snprintf(namebuf, sizeof(namebuf), "%s/%s", dir, dp->d_name);
|
||||
TIMEOUT(rval = stat(namebuf, &sbuf));
|
||||
if (rval == -1 && errno != ENOENT) {
|
||||
/*
|
||||
@@ -1336,7 +1336,7 @@ static int trim_finfo(FINFO **fp)
|
||||
* Versionless is not linked to any versioned
|
||||
* file.
|
||||
*/
|
||||
sprintf(ver, ";%u", mp->version + 1);
|
||||
snprintf(ver, sizeof(ver), ";%u", mp->version + 1);
|
||||
strcat(sp->lname, ver);
|
||||
sp->lname_len = strlen(sp->lname);
|
||||
pnum = ++num;
|
||||
@@ -1464,7 +1464,7 @@ static int trim_finfo_highest(FINFO **fp, int highestp)
|
||||
* Versionless is not linked to any versioned
|
||||
* file.
|
||||
*/
|
||||
sprintf(ver, ";%u", mp->version + 1);
|
||||
snprintf(ver, sizeof(ver), ";%u", mp->version + 1);
|
||||
strcat(sp->lname, ver);
|
||||
sp->lname_len = strlen(sp->lname);
|
||||
/*
|
||||
@@ -1646,7 +1646,7 @@ static int trim_finfo_version(FINFO **fp, unsigned rver)
|
||||
* file.
|
||||
*/
|
||||
if (mp->version + 1 == rver) {
|
||||
sprintf(ver, ";%u", rver);
|
||||
snprintf(ver, sizeof(ver), ";%u", rver);
|
||||
strcat(sp->lname, ver);
|
||||
sp->lname_len = strlen(sp->lname);
|
||||
/*
|
||||
|
||||
36
src/dsk.c
36
src/dsk.c
@@ -11,7 +11,7 @@
|
||||
|
||||
#include <errno.h> // for errno, EINTR, ENOENT, ENFILE, EPERM
|
||||
#include <fcntl.h> // for O_RDWR, O_CREAT, open, O_RDONLY, O_TRUNC
|
||||
#include <stdio.h> // for NULL, sprintf, size_t, rename, SEEK_SET
|
||||
#include <stdio.h> // for NULL, snprintf, size_t, rename, SEEK_SET
|
||||
#include <stddef.h> // for ptrdiff_t
|
||||
#include <stdlib.h> // for strtoul, qsort
|
||||
#include <string.h> // for strlcpy, strcmp, strlen, strncpy, strchr
|
||||
@@ -662,7 +662,7 @@ LispPTR COM_closefile(LispPTR *args)
|
||||
}
|
||||
|
||||
for (; rval == 0; S_TOUT(rval = _dos_findnext(&dirp))) {
|
||||
sprintf(file, "%s\\%s", dir, dirp.name);
|
||||
snprintf(file, sizeof(file), "%s\\%s", dir, dirp.name);
|
||||
}
|
||||
}
|
||||
#ifndef DOS /* effectively NEVER, since we're in an ifdef DOS */
|
||||
@@ -2358,7 +2358,7 @@ void separate_version(char *name, char *ver, int checkp)
|
||||
* Use strtoul() to eliminate leading 0s.
|
||||
*/
|
||||
ver_no = strtoul(start + 1, (char **)NULL, 10);
|
||||
sprintf(ver_buf, "%u", ver_no);
|
||||
snprintf(ver_buf, sizeof(ver_buf), "%u", ver_no);
|
||||
strlcpy(ver, ver_buf, sizeof(ver));
|
||||
return;
|
||||
} else {
|
||||
@@ -2638,7 +2638,7 @@ static int locate_file(char *dir, char *name)
|
||||
struct direct *dp;
|
||||
|
||||
/* First of all, recognize as if. */
|
||||
sprintf(path, "%s\\%s", dir, name);
|
||||
snprintf(path, sizeof(path), "%s\\%s", dir, name);
|
||||
DIR_OR_FILE_P(path, type);
|
||||
if (type != 0) {
|
||||
strlcpy(dir, path, sizeof(dir));
|
||||
@@ -2657,7 +2657,7 @@ static int locate_file(char *dir, char *name)
|
||||
struct dirent *dp;
|
||||
|
||||
/* First of all, recognize as if. */
|
||||
sprintf(path, "%s/%s", dir, name);
|
||||
snprintf(path, sizeof(path), "%s/%s", dir, name);
|
||||
DIR_OR_FILE_P(path, type);
|
||||
if (type != 0) {
|
||||
strlcpy(dir, path, sizeof(dir));
|
||||
@@ -2667,7 +2667,7 @@ static int locate_file(char *dir, char *name)
|
||||
/* Next try with all lower case name. */
|
||||
strlcpy(nb1, name, sizeof(nb1));
|
||||
DOWNCASE(nb1);
|
||||
sprintf(path, "%s/%s", dir, nb1);
|
||||
snprintf(path, sizeof(path), "%s/%s", dir, nb1);
|
||||
DIR_OR_FILE_P(path, type);
|
||||
if (type != 0) {
|
||||
strlcpy(dir, path, sizeof(dir));
|
||||
@@ -2676,7 +2676,7 @@ static int locate_file(char *dir, char *name)
|
||||
|
||||
/* Next try with all upper case name. */
|
||||
UPCASE(nb1);
|
||||
sprintf(path, "%s/%s", dir, nb1);
|
||||
snprintf(path, sizeof(path), "%s/%s", dir, nb1);
|
||||
DIR_OR_FILE_P(path, type);
|
||||
if (type != 0) {
|
||||
strlcpy(dir, path, sizeof(dir));
|
||||
@@ -2698,7 +2698,7 @@ static int locate_file(char *dir, char *name)
|
||||
strlcpy(nb2, dp->d_name, sizeof(nb2));
|
||||
UPCASE(nb2);
|
||||
if (strcmp(nb1, nb2) == 0) {
|
||||
sprintf(path, "%s/%s", dir, dp->d_name);
|
||||
snprintf(path, sizeof(path), "%s/%s", dir, dp->d_name);
|
||||
DIR_OR_FILE_P(path, type);
|
||||
if (type != 0) {
|
||||
strlcpy(dir, path, sizeof(dir));
|
||||
@@ -3329,7 +3329,7 @@ static int maintain_version(char *file, int forcep)
|
||||
* is versioned one higher than the existing highest version.
|
||||
*/
|
||||
FindHighestVersion(VA.files, entry, max_no);
|
||||
sprintf(ver, "%u", max_no + 1);
|
||||
snprintf(ver, sizeof(ver), "%u", max_no + 1);
|
||||
/*
|
||||
* The old file should have the same case name as the versionless
|
||||
* file.
|
||||
@@ -3653,7 +3653,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile)
|
||||
* link missing versionless file.
|
||||
*/
|
||||
FindHighestVersion(varray, entry, max_no);
|
||||
sprintf(vbuf, "%u", max_no + 1);
|
||||
snprintf(vbuf, sizeof(vbuf), "%u", max_no + 1);
|
||||
conc_name_and_version(vless, vbuf, vfile, sizeof(vfile));
|
||||
strlcpy(afile, vless, sizeof(afile));
|
||||
return (1);
|
||||
@@ -3668,7 +3668,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile)
|
||||
* is dealt with as a version of the link
|
||||
* missing versionless file.
|
||||
*/
|
||||
sprintf(vbuf, "%u", ver_no);
|
||||
snprintf(vbuf, sizeof(vbuf), "%u", ver_no);
|
||||
conc_name_and_version(vless, vbuf, vfile, sizeof(vfile));
|
||||
strlcpy(afile, vless, sizeof(afile));
|
||||
return (1);
|
||||
@@ -3864,7 +3864,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile)
|
||||
* is dealt with as a version of the link
|
||||
* missing versionless file.
|
||||
*/
|
||||
sprintf(vbuf, "%u", ver_no);
|
||||
snprintf(vbuf, sizeof(vbuf), "%u", ver_no);
|
||||
conc_name_and_version(vless, vbuf, vfile, sizeof(vfile));
|
||||
strlcpy(afile, vless, sizeof(afile));
|
||||
return (1);
|
||||
@@ -4009,7 +4009,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile)
|
||||
* the existing highest version.
|
||||
*/
|
||||
FindHighestVersion(varray, entry, max_no);
|
||||
sprintf(vbuf, "%u", max_no + 1);
|
||||
snprintf(vbuf, sizeof(vbuf), "%u", max_no + 1);
|
||||
/*
|
||||
* We will use the file name of the existing highest
|
||||
* versioned file as the name of the new file, so that
|
||||
@@ -4101,7 +4101,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile)
|
||||
* missing versionless file.
|
||||
*/
|
||||
FindHighestVersion(varray, entry, max_no);
|
||||
sprintf(vbuf, "%u", max_no + 2);
|
||||
snprintf(vbuf, sizeof(vbuf), "%u", max_no + 2);
|
||||
conc_name_and_version(vless, vbuf, vfile, sizeof(vfile));
|
||||
strlcpy(afile, vfile, sizeof(afile));
|
||||
return (1);
|
||||
@@ -4116,7 +4116,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile)
|
||||
* is dealt with as a version of the link
|
||||
* missing versionless file.
|
||||
*/
|
||||
sprintf(vbuf, "%u", ver_no);
|
||||
snprintf(vbuf, sizeof(vbuf), "%u", ver_no);
|
||||
conc_name_and_version(vless, vbuf, vfile, sizeof(vfile));
|
||||
strlcpy(afile, vless, sizeof(afile));
|
||||
return (1);
|
||||
@@ -4164,7 +4164,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile)
|
||||
* new file.
|
||||
*/
|
||||
FindHighestVersion(varray, entry, max_no);
|
||||
sprintf(vbuf, "%u", max_no + 1);
|
||||
snprintf(vbuf, sizeof(vbuf), "%u", max_no + 1);
|
||||
/*
|
||||
* We will use the name of the highest versioned file
|
||||
* as the name of the new file.
|
||||
@@ -4380,7 +4380,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile)
|
||||
* link missing versionless file.
|
||||
*/
|
||||
FindHighestVersion(varray, entry, max_no);
|
||||
sprintf(vbuf, "%u", max_no + 1);
|
||||
snprintf(vbuf, sizeof(vbuf), "%u", max_no + 1);
|
||||
conc_name_and_version(vless, vbuf, vfile, sizeof(vfile));
|
||||
strlcpy(afile, vless, sizeof(afile));
|
||||
return (1);
|
||||
@@ -4395,7 +4395,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile)
|
||||
* is dealt with as a version of the link
|
||||
* missing versionless file.
|
||||
*/
|
||||
sprintf(vbuf, "%u", ver_no);
|
||||
snprintf(vbuf, sizeof(vbuf), "%u", ver_no);
|
||||
conc_name_and_version(vless, vbuf, vfile, sizeof(vfile));
|
||||
strlcpy(afile, vless, sizeof(afile));
|
||||
return (1);
|
||||
|
||||
@@ -351,7 +351,7 @@ LispPTR vmem_save(char *sysout_file_name)
|
||||
/* Bloddy 8 char filenames in dos ... /jarl */
|
||||
make_old_version(tempname, sysout_file_name);
|
||||
#else /* DOS */
|
||||
sprintf(tempname, "%s-temp", sysout_file_name);
|
||||
snprintf(tempname, sizeof(tempname), "%s-temp", sysout_file_name);
|
||||
#endif /* DOS */
|
||||
|
||||
/* Confirm protection of specified file by open/close */
|
||||
|
||||
Reference in New Issue
Block a user