From af2ac7ccc66451bffb458f82f3110c59faba80df Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 1 Feb 2011 14:54:08 -0500 Subject: [PATCH] Use a char array to map a number to a base36 digit. --- plugins/sudoers/iolog.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/sudoers/iolog.c b/plugins/sudoers/iolog.c index 3a83d0781..976c49241 100644 --- a/plugins/sudoers/iolog.c +++ b/plugins/sudoers/iolog.c @@ -137,11 +137,12 @@ io_nextid(char *iolog_dir, char sessid[7]) { struct stat sb; char buf[32], *ep; - int fd, i, ch; + int fd, i; unsigned long id = 0; int len; ssize_t nread; char pathbuf[PATH_MAX]; + static const char b36char[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; /* * Create I/O log directory if it doesn't already exist. @@ -184,9 +185,8 @@ io_nextid(char *iolog_dir, char sessid[7]) * Note that that least significant digits go at the end of the string. */ for (i = 5; i >= 0; i--) { - ch = id % 36; + buf[i] = b36char[id % 36]; id /= 36; - buf[i] = ch < 10 ? ch + '0' : ch - 10 + 'A'; } buf[6] = '\n';