From: Todd C. Miller Date: Tue, 1 Feb 2011 19:54:08 +0000 (-0500) Subject: Use a char array to map a number to a base36 digit. X-Git-Tag: SUDO_1_8_0~44 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=af2ac7ccc66451bffb458f82f3110c59faba80df;p=sudo Use a char array to map a number to a base36 digit. --- 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';