[前][次][番号順一覧][スレッド一覧]

ruby-changes:62682

From: Kazuhiro <ko1@a...>
Date: Sat, 22 Aug 2020 09:40:04 +0900 (JST)
Subject: [ruby-changes:62682] 1ab6034529 (master): Fix type of getlogin_r's 2nd argument

https://git.ruby-lang.org/ruby.git/commit/?id=1ab6034529

From 1ab60345297aa5130cebc98063158059951bc407 Mon Sep 17 00:00:00 2001
From: Kazuhiro NISHIYAMA <zn@m...>
Date: Sat, 22 Aug 2020 09:33:45 +0900
Subject: 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

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) https://github.com/ruby/ruby/blob/trunk/process.c#L5577
 
 # 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) https://github.com/ruby/ruby/blob/trunk/process.c#L5596
 
     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);
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]