summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKazuhiro NISHIYAMA <zn@mbf.nifty.com>2020-08-22 09:33:45 +0900
committerKazuhiro NISHIYAMA <zn@mbf.nifty.com>2020-08-22 09:39:24 +0900
commit1ab60345297aa5130cebc98063158059951bc407 (patch)
treec40f9d4d708011479d9995c4b4bf87af2a7dc35f
parenta0273d67d044dc9fe25313e0854a33374b990e8a (diff)
Fix type of getlogin_r's 2nd argument
https://rubyci.org/logs/rubyci.s3.amazonaws.com/freebsd12/ruby-master/log/20200821T223002Z.fail.html.gz ``` process.c:5593:37: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32] while ((gle = getlogin_r(login, loginsize)) != 0) { ~~~~~~~~~~ ^~~~~~~~~ ``` type of getlogin_r's 2nd argument is - int on FreeBSD - https://www.freebsd.org/cgi/man.cgi?query=getlogin_r&apropos=0&sektion=0&manpath=FreeBSD+12.1-RELEASE+and+Ports&arch=default&format=html - size_t on Linux, NetBSD - https://man7.org/linux/man-pages/man3/getlogin_r.3.html - https://www.freebsd.org/cgi/man.cgi?query=getlogin_r&apropos=0&sektion=0&manpath=NetBSD+9.0&arch=default&format=html
-rw-r--r--process.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/process.c b/process.c
index 0a97425..fb8d26a 100644
--- a/process.c
+++ b/process.c
@@ -5577,6 +5577,12 @@ rb_getlogin(void)
# ifdef USE_GETLOGIN_R
+#if defined(__FreeBSD__)
+ typedef int getlogin_r_size_t;
+#else
+ typedef size_t getlogin_r_size_t;
+#endif
+
long loginsize = GETLOGIN_R_SIZE_INIT; /* maybe -1 */
if (loginsize < 0)
@@ -5590,7 +5596,7 @@ rb_getlogin(void)
int gle;
errno = 0;
- while ((gle = getlogin_r(login, loginsize)) != 0) {
+ while ((gle = getlogin_r(login, (getlogin_r_size_t)loginsize)) != 0) {
if (gle == ENOTTY || gle == ENXIO || gle == ENOENT) {
rb_str_resize(maybe_result, 0);