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
This commit is contained in:
Kazuhiro NISHIYAMA 2020-08-22 09:33:45 +09:00
parent a0273d67d0
commit 1ab6034529
No known key found for this signature in database
GPG Key ID: 262ED8DBB4222F7A

View File

@ -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);