Skip to content

Commit 4f79f55

Browse files
authored
Replace uses of atoi() with strtol() or stroul() as appropriate (#394)
As a side-effect of this change, we also resolve a a problem with signed file version numbers, so that instead of version 2147483647 wrapping to -2147483648 we can go as far as 4294967296 before we have issues. Various sprintf() formats get changed from %d to %u. The DOS version code is left behind as int versions.
1 parent 85c4ebf commit 4f79f55

File tree

10 files changed

+125
-76
lines changed

10 files changed

+125
-76
lines changed

inc/lispver1.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
NumericStringP(vp, YES, NO); \
4040
NO: *vp = 0; \
4141
YES: \
42-
if ((*vp)) ver = atoi(vp); \
42+
if ((*vp)) ver = strtol(vp, (char **)NULL, 10); \
4343
else ver = -1; \
4444
} \
4545
else ver = -1; \

inc/lispver2.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
\
99
register char *lv_cp; \
1010
register char *lv_vp; \
11-
register int lv_ver; \
11+
register unsigned lv_ver; \
1212
char lv_ver_buf[VERSIONLEN]; \
1313
\
1414
lv_cp = pathname; \
@@ -48,20 +48,20 @@
4848
/* \
4949
* Convert the remaining field to digit. \
5050
*/ \
51-
lv_ver = atoi(lv_vp + 1); \
52-
if (lv_ver == 0) { \
51+
lv_ver = strtoul(lv_vp + 1, (char **)NULL, 10); \
52+
if (lv_ver == 0) { \
5353
/* versionless */ \
5454
*lv_vp = 0; \
5555
} else { \
56-
sprintf(lv_ver_buf, ".~%d~", lv_ver); \
56+
sprintf(lv_ver_buf, ".~%u~", lv_ver); \
5757
*lv_vp = 0; \
5858
strcat(pathname, lv_ver_buf); \
5959
} \
6060
goto CONT; \
6161
\
6262
NO: \
6363
strcpy(lv_ver_buf, lv_vp + 1); \
64-
strcat(lv_ver_buf, "~"); \
64+
strcat(lv_ver_buf, "~"); \
6565
*lv_vp++ = '.'; \
6666
*lv_vp++ = '~'; \
6767
*lv_vp = 0; \

inc/locfile.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,9 @@ extern DLword *Lisp_world; /* To access LispSysout area */
385385
*(start - 1) = ';'; \
386386
*start = '\0'; \
387387
*end = '\0'; \
388-
/* call ato i to eliminate leading 0s. */ \
389-
ver_no = atoi(start + 1); \
390-
sprintf(ver_buf, "%d", ver_no); \
388+
/* call strtoul() to eliminate leading 0s. */ \
389+
ver_no = strtoul(start + 1, (char **)NULL, 10); \
390+
sprintf(ver_buf, "%u", ver_no); \
391391
strcat(pathname, ver_buf); \
392392
goto CONT; \
393393
\
@@ -494,7 +494,7 @@ extern DLword *Lisp_world; /* To access LispSysout area */
494494

495495
#define MAXVERSION 999999999
496496

497-
#define LASTVERSIONARRAY (-1)
497+
#define LASTVERSIONARRAY ((unsigned) -1)
498498
#define VERSIONARRAYLENGTH 200
499499

500500
#define NoFileP(varray) \

src/dir.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ void print_finfo(FINFO *fp)
329329
if (fp != (FINFO *)NULL) {
330330
do {
331331
printf("%s -> ", fp->lname);
332-
printf("%d\n", fp->version);
332+
printf("%u\n", fp->version);
333333
fp = fp->next;
334334
} while (fp != (FINFO *)NULL && fp != sp);
335335

@@ -685,7 +685,7 @@ static int enum_dsk_prop(char *dir, char *name, char *ver, FINFO **finfo_buf)
685685
if (*fver == '\0')
686686
nextp->version = 0;
687687
else
688-
nextp->version = atoi(fver);
688+
nextp->version = strtoul(fver, (char **)NULL, 10);
689689
nextp->ino = sbuf.st_ino;
690690
nextp->prop->length = (unsigned)sbuf.st_size;
691691
nextp->prop->wdate = (unsigned)ToLispTime(sbuf.st_mtime);
@@ -948,7 +948,7 @@ static int enum_dsk(char *dir, char *name, char *ver, FINFO **finfo_buf)
948948
if (*fver == '\0')
949949
nextp->version = 0;
950950
else
951-
nextp->version = atoi(fver);
951+
nextp->version = strtoul(fver, (char **)NULL, 10);
952952
nextp->ino = sbuf.st_ino;
953953
n++;
954954
}
@@ -1399,7 +1399,7 @@ static int trim_finfo(FINFO **fp)
13991399
* Versionless is not linked to any versioned
14001400
* file.
14011401
*/
1402-
sprintf(ver, ";%d", mp->version + 1);
1402+
sprintf(ver, ";%u", mp->version + 1);
14031403
strcat(sp->lname, ver);
14041404
sp->lname_len = strlen(sp->lname);
14051405
pnum = ++num;
@@ -1527,7 +1527,7 @@ static int trim_finfo_highest(FINFO **fp, int highestp)
15271527
* Versionless is not linked to any versioned
15281528
* file.
15291529
*/
1530-
sprintf(ver, ";%d", mp->version + 1);
1530+
sprintf(ver, ";%u", mp->version + 1);
15311531
strcat(sp->lname, ver);
15321532
sp->lname_len = strlen(sp->lname);
15331533
/*
@@ -1709,7 +1709,7 @@ static int trim_finfo_version(FINFO **fp, int rver)
17091709
* file.
17101710
*/
17111711
if (mp->version + 1 == rver) {
1712-
sprintf(ver, ";%d", rver);
1712+
sprintf(ver, ";%u", rver);
17131713
strcat(sp->lname, ver);
17141714
sp->lname_len = strlen(sp->lname);
17151715
/*
@@ -2111,7 +2111,7 @@ LispPTR COM_gen_files(register LispPTR *args)
21112111

21122112
if (*ver != '\0') {
21132113
highestp = 0;
2114-
version = atoi(ver);
2114+
version = strtoul(ver, (char **)NULL, 10);
21152115
if (version > 0) strcpy(ver, "*");
21162116
} else {
21172117
version = 0;

0 commit comments

Comments
 (0)