1111
1212#include <errno.h> // for errno, EINTR, ENOENT, ENFILE, EPERM
1313#include <fcntl.h> // for O_RDWR, O_CREAT, open, O_RDONLY, O_TRUNC
14- #include <stdio.h> // for NULL, sprintf , size_t, rename, SEEK_SET
14+ #include <stdio.h> // for NULL, snprintf , size_t, rename, SEEK_SET
1515#include <stddef.h> // for ptrdiff_t
1616#include <stdlib.h> // for strtoul, qsort
1717#include <string.h> // for strlcpy, strcmp, strlen, strncpy, strchr
@@ -662,7 +662,7 @@ LispPTR COM_closefile(LispPTR *args)
662662 }
663663
664664 for (; rval == 0 ; S_TOUT (rval = _dos_findnext (& dirp ))) {
665- sprintf (file , "%s\\%s" , dir , dirp .name );
665+ snprintf (file , sizeof ( file ) , "%s\\%s" , dir , dirp .name );
666666 }
667667 }
668668#ifndef DOS /* effectively NEVER, since we're in an ifdef DOS */
@@ -2358,7 +2358,7 @@ void separate_version(char *name, char *ver, int checkp)
23582358 * Use strtoul() to eliminate leading 0s.
23592359 */
23602360 ver_no = strtoul (start + 1 , (char * * )NULL , 10 );
2361- sprintf (ver_buf , "%u" , ver_no );
2361+ snprintf (ver_buf , sizeof ( ver_buf ) , "%u" , ver_no );
23622362 strlcpy (ver , ver_buf , sizeof (ver ));
23632363 return ;
23642364 } else {
@@ -2638,7 +2638,7 @@ static int locate_file(char *dir, char *name)
26382638 struct direct * dp ;
26392639
26402640 /* First of all, recognize as if. */
2641- sprintf (path , "%s\\%s" , dir , name );
2641+ snprintf (path , sizeof ( path ) , "%s\\%s" , dir , name );
26422642 DIR_OR_FILE_P (path , type );
26432643 if (type != 0 ) {
26442644 strlcpy (dir , path , sizeof (dir ));
@@ -2657,7 +2657,7 @@ static int locate_file(char *dir, char *name)
26572657 struct dirent * dp ;
26582658
26592659 /* First of all, recognize as if. */
2660- sprintf (path , "%s/%s" , dir , name );
2660+ snprintf (path , sizeof ( path ) , "%s/%s" , dir , name );
26612661 DIR_OR_FILE_P (path , type );
26622662 if (type != 0 ) {
26632663 strlcpy (dir , path , sizeof (dir ));
@@ -2667,7 +2667,7 @@ static int locate_file(char *dir, char *name)
26672667 /* Next try with all lower case name. */
26682668 strlcpy (nb1 , name , sizeof (nb1 ));
26692669 DOWNCASE (nb1 );
2670- sprintf (path , "%s/%s" , dir , nb1 );
2670+ snprintf (path , sizeof ( path ) , "%s/%s" , dir , nb1 );
26712671 DIR_OR_FILE_P (path , type );
26722672 if (type != 0 ) {
26732673 strlcpy (dir , path , sizeof (dir ));
@@ -2676,7 +2676,7 @@ static int locate_file(char *dir, char *name)
26762676
26772677 /* Next try with all upper case name. */
26782678 UPCASE (nb1 );
2679- sprintf (path , "%s/%s" , dir , nb1 );
2679+ snprintf (path , sizeof ( path ) , "%s/%s" , dir , nb1 );
26802680 DIR_OR_FILE_P (path , type );
26812681 if (type != 0 ) {
26822682 strlcpy (dir , path , sizeof (dir ));
@@ -2698,7 +2698,7 @@ static int locate_file(char *dir, char *name)
26982698 strlcpy (nb2 , dp -> d_name , sizeof (nb2 ));
26992699 UPCASE (nb2 );
27002700 if (strcmp (nb1 , nb2 ) == 0 ) {
2701- sprintf (path , "%s/%s" , dir , dp -> d_name );
2701+ snprintf (path , sizeof ( path ) , "%s/%s" , dir , dp -> d_name );
27022702 DIR_OR_FILE_P (path , type );
27032703 if (type != 0 ) {
27042704 strlcpy (dir , path , sizeof (dir ));
@@ -3329,7 +3329,7 @@ static int maintain_version(char *file, int forcep)
33293329 * is versioned one higher than the existing highest version.
33303330 */
33313331 FindHighestVersion (VA .files , entry , max_no );
3332- sprintf (ver , "%u" , max_no + 1 );
3332+ snprintf (ver , sizeof ( ver ) , "%u" , max_no + 1 );
33333333/*
33343334 * The old file should have the same case name as the versionless
33353335 * file.
@@ -3653,7 +3653,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile)
36533653 * link missing versionless file.
36543654 */
36553655 FindHighestVersion (varray , entry , max_no );
3656- sprintf (vbuf , "%u" , max_no + 1 );
3656+ snprintf (vbuf , sizeof ( vbuf ) , "%u" , max_no + 1 );
36573657 conc_name_and_version (vless , vbuf , vfile , sizeof (vfile ));
36583658 strlcpy (afile , vless , sizeof (afile ));
36593659 return (1 );
@@ -3668,7 +3668,7 @@ static int get_old(char *dir, FileName *varray, char *afile, char *vfile)
36683668 * is dealt with as a version of the link
36693669 * missing versionless file.
36703670 */
3671- sprintf (vbuf , "%u" , ver_no );
3671+ snprintf (vbuf , sizeof ( vbuf ) , "%u" , ver_no );
36723672 conc_name_and_version (vless , vbuf , vfile , sizeof (vfile ));
36733673 strlcpy (afile , vless , sizeof (afile ));
36743674 return (1 );
@@ -3864,7 +3864,7 @@ static int get_oldest(char *dir, FileName *varray, char *afile, char *vfile)
38643864 * is dealt with as a version of the link
38653865 * missing versionless file.
38663866 */
3867- sprintf (vbuf , "%u" , ver_no );
3867+ snprintf (vbuf , sizeof ( vbuf ) , "%u" , ver_no );
38683868 conc_name_and_version (vless , vbuf , vfile , sizeof (vfile ));
38693869 strlcpy (afile , vless , sizeof (afile ));
38703870 return (1 );
@@ -4009,7 +4009,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile)
40094009 * the existing highest version.
40104010 */
40114011 FindHighestVersion (varray , entry , max_no );
4012- sprintf (vbuf , "%u" , max_no + 1 );
4012+ snprintf (vbuf , sizeof ( vbuf ) , "%u" , max_no + 1 );
40134013 /*
40144014 * We will use the file name of the existing highest
40154015 * 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)
41014101 * missing versionless file.
41024102 */
41034103 FindHighestVersion (varray , entry , max_no );
4104- sprintf (vbuf , "%u" , max_no + 2 );
4104+ snprintf (vbuf , sizeof ( vbuf ) , "%u" , max_no + 2 );
41054105 conc_name_and_version (vless , vbuf , vfile , sizeof (vfile ));
41064106 strlcpy (afile , vfile , sizeof (afile ));
41074107 return (1 );
@@ -4116,7 +4116,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile)
41164116 * is dealt with as a version of the link
41174117 * missing versionless file.
41184118 */
4119- sprintf (vbuf , "%u" , ver_no );
4119+ snprintf (vbuf , sizeof ( vbuf ) , "%u" , ver_no );
41204120 conc_name_and_version (vless , vbuf , vfile , sizeof (vfile ));
41214121 strlcpy (afile , vless , sizeof (afile ));
41224122 return (1 );
@@ -4164,7 +4164,7 @@ static int get_new(char *dir, FileName *varray, char *afile, char *vfile)
41644164 * new file.
41654165 */
41664166 FindHighestVersion (varray , entry , max_no );
4167- sprintf (vbuf , "%u" , max_no + 1 );
4167+ snprintf (vbuf , sizeof ( vbuf ) , "%u" , max_no + 1 );
41684168 /*
41694169 * We will use the name of the highest versioned file
41704170 * as the name of the new file.
@@ -4380,7 +4380,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile)
43804380 * link missing versionless file.
43814381 */
43824382 FindHighestVersion (varray , entry , max_no );
4383- sprintf (vbuf , "%u" , max_no + 1 );
4383+ snprintf (vbuf , sizeof ( vbuf ) , "%u" , max_no + 1 );
43844384 conc_name_and_version (vless , vbuf , vfile , sizeof (vfile ));
43854385 strlcpy (afile , vless , sizeof (afile ));
43864386 return (1 );
@@ -4395,7 +4395,7 @@ static int get_old_new(char *dir, FileName *varray, char *afile, char *vfile)
43954395 * is dealt with as a version of the link
43964396 * missing versionless file.
43974397 */
4398- sprintf (vbuf , "%u" , ver_no );
4398+ snprintf (vbuf , sizeof ( vbuf ) , "%u" , ver_no );
43994399 conc_name_and_version (vless , vbuf , vfile , sizeof (vfile ));
44004400 strlcpy (afile , vless , sizeof (afile ));
44014401 return (1 );
0 commit comments