From b23b6bbcf776563e9d517fb307e923bb1d33fff7 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 14 Sep 1995 13:31:52 +0000 Subject: (tempname): Replace `16' with a more readable expansion. Make sure that SEQ never exceeds 99999. --- src/sort.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/sort.c b/src/sort.c index d0ceb5947..89e7e8085 100644 --- a/src/sort.c +++ b/src/sort.c @@ -314,17 +314,23 @@ xfwrite (buf, size, nelem, fp) static char * tempname () { - static int seq; + static unsigned int seq; int len = strlen (temp_file_prefix); - char *name = xmalloc (len + 16); - struct tempnode *node = - (struct tempnode *) xmalloc (sizeof (struct tempnode)); + char *name = xmalloc (len + 1 + sizeof ("sort") - 1 + 5 + 5 + 1); + struct tempnode *node; + node = (struct tempnode *) xmalloc (sizeof (struct tempnode)); sprintf (name, "%s%ssort%5.5d%5.5d", temp_file_prefix, (len && temp_file_prefix[len - 1] != '/') ? "/" : "", - (unsigned int) getpid () & 0xffff, ++seq); + (unsigned int) getpid () & 0xffff, seq); + + /* Make sure that SEQ's value fits in 5 digits. */ + ++seq; + if (seq >= 100000) + seq = 0; + node->name = name; node->next = temphead.next; temphead.next = node; @@ -657,7 +663,8 @@ numcompare (a, b) { register int tmpa, tmpb, loga, logb, tmp; - tmpa = UCHAR (*a), tmpb = UCHAR (*b); + tmpa = UCHAR (*a); + tmpb = UCHAR (*b); while (blanks[tmpa]) tmpa = UCHAR (*++a); -- cgit v1.2.3-70-g09d2