diff options
| author | Paul Eggert | 2011-08-28 16:59:14 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-08-28 16:59:14 -0700 |
| commit | 0c6d656d269f84c83c483057eac6081eddfd33a0 (patch) | |
| tree | 99a3d309b3fbb6572e3cb65c8402cab635b92092 | |
| parent | 644a0faa36ad8c1e251d198c2bc69f17c8bdb83a (diff) | |
| download | emacs-0c6d656d269f84c83c483057eac6081eddfd33a0.tar.gz emacs-0c6d656d269f84c83c483057eac6081eddfd33a0.zip | |
* update-game-score.c: Include <limits.h>
(get_user_id): Do not assume uid fits in 'int'. Simplify.
| -rw-r--r-- | lib-src/ChangeLog | 3 | ||||
| -rw-r--r-- | lib-src/update-game-score.c | 15 |
2 files changed, 8 insertions, 10 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index ca08ece7c39..a888a8cdd1c 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog | |||
| @@ -30,6 +30,9 @@ | |||
| 30 | in 'int'. Instead, put the possibly-long file name into the | 30 | in 'int'. Instead, put the possibly-long file name into the |
| 31 | output of pfatal_with_name. | 31 | output of pfatal_with_name. |
| 32 | 32 | ||
| 33 | * update-game-score.c: Include <limits.h> | ||
| 34 | (get_user_id): Do not assume uid fits in 'int'. Simplify. | ||
| 35 | |||
| 33 | 2011-07-28 Paul Eggert <eggert@cs.ucla.edu> | 36 | 2011-07-28 Paul Eggert <eggert@cs.ucla.edu> |
| 34 | 37 | ||
| 35 | Assume freestanding C89 headers, string.h, stdlib.h. | 38 | Assume freestanding C89 headers, string.h, stdlib.h. |
diff --git a/lib-src/update-game-score.c b/lib-src/update-game-score.c index 2a89379aefe..9fba51a33de 100644 --- a/lib-src/update-game-score.c +++ b/lib-src/update-game-score.c | |||
| @@ -35,6 +35,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 35 | 35 | ||
| 36 | #include <unistd.h> | 36 | #include <unistd.h> |
| 37 | #include <errno.h> | 37 | #include <errno.h> |
| 38 | #include <limits.h> | ||
| 38 | #include <string.h> | 39 | #include <string.h> |
| 39 | #include <stdlib.h> | 40 | #include <stdlib.h> |
| 40 | #include <stdio.h> | 41 | #include <stdio.h> |
| @@ -128,19 +129,13 @@ lose_syserr (const char *msg) | |||
| 128 | static char * | 129 | static char * |
| 129 | get_user_id (void) | 130 | get_user_id (void) |
| 130 | { | 131 | { |
| 131 | char *name; | ||
| 132 | struct passwd *buf = getpwuid (getuid ()); | 132 | struct passwd *buf = getpwuid (getuid ()); |
| 133 | if (!buf) | 133 | if (!buf) |
| 134 | { | 134 | { |
| 135 | int count = 1; | 135 | long uid = getuid (); |
| 136 | int uid = (int) getuid (); | 136 | char *name = malloc (sizeof uid * CHAR_BIT / 3 + 1); |
| 137 | int tuid = uid; | 137 | if (name) |
| 138 | while (tuid /= 10) | 138 | sprintf (name, "%ld", uid); |
| 139 | count++; | ||
| 140 | name = malloc (count+1); | ||
| 141 | if (!name) | ||
| 142 | return NULL; | ||
| 143 | sprintf (name, "%d", uid); | ||
| 144 | return name; | 139 | return name; |
| 145 | } | 140 | } |
| 146 | return buf->pw_name; | 141 | return buf->pw_name; |