From: Paul Eggert Date: Sun, 28 Aug 2011 23:59:14 +0000 (-0700) Subject: * update-game-score.c: Include X-Git-Tag: emacs-pretest-24.0.90~104^2~153^2~1^2~36 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0c6d656d269f84c83c483057eac6081eddfd33a0;p=emacs.git * update-game-score.c: Include (get_user_id): Do not assume uid fits in 'int'. Simplify. --- 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 @@ in 'int'. Instead, put the possibly-long file name into the output of pfatal_with_name. + * update-game-score.c: Include + (get_user_id): Do not assume uid fits in 'int'. Simplify. + 2011-07-28 Paul Eggert 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 . */ #include #include +#include #include #include #include @@ -128,19 +129,13 @@ lose_syserr (const char *msg) static char * get_user_id (void) { - char *name; struct passwd *buf = getpwuid (getuid ()); if (!buf) { - int count = 1; - int uid = (int) getuid (); - int tuid = uid; - while (tuid /= 10) - count++; - name = malloc (count+1); - if (!name) - return NULL; - sprintf (name, "%d", uid); + long uid = getuid (); + char *name = malloc (sizeof uid * CHAR_BIT / 3 + 1); + if (name) + sprintf (name, "%ld", uid); return name; } return buf->pw_name;