From: Michael Beck Date: Sat, 19 Apr 2008 17:55:32 +0000 (+0000) Subject: - handle failure of getpwuid() more gracefully X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=06fc4c9dd220fd3a30adce4ef639efd50186cdf8;p=libfirm - handle failure of getpwuid() more gracefully [r19335] --- diff --git a/ir/libcore/lc_opts.c b/ir/libcore/lc_opts.c index ff472c690..757dde8a0 100644 --- a/ir/libcore/lc_opts.c +++ b/ir/libcore/lc_opts.c @@ -911,11 +911,19 @@ void lc_opts_init(const char *ini_name, lc_opt_entry_t *root, const char *arg_pr strncpy(home_dir_ini_file, local_ini_file, sizeof(home_dir_ini_file)); home_dir_ini_file[sizeof(home_dir_ini_file) - 1] = '\0'; #else - strcpy(path, getpwuid(getuid())->pw_dir); - strncat(path, "/", sizeof(path)); - /* .rc */ - snprintf(home_dir_ini_file, sizeof(home_dir_ini_file), ".%src", ini_name); - home_dir_ini_file[sizeof(home_dir_ini_file) - 1] = '\0'; + { + struct passwd *entry = getpwuid(getuid()); + if (entry != NULL) { + strcpy(path, entry->pw_dir); + strncat(path, "/", sizeof(path)); + /* .rc */ + snprintf(home_dir_ini_file, sizeof(home_dir_ini_file), ".%src", ini_name); + home_dir_ini_file[sizeof(home_dir_ini_file) - 1] = '\0'; + } else { + /* FIXME: some error occured */ + home_dir_ini_file[0] = '\0';' + } + } #endif strncat(path, home_dir_ini_file, sizeof(path));