Skip to content

Commit

Permalink
Fix type of getlogin_r's 2nd argument
Browse files Browse the repository at this point in the history
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
  • Loading branch information
znz committed Aug 22, 2020
1 parent a0273d6 commit 1ab6034
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion process.c
Expand Up @@ -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)
Expand All @@ -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);
Expand Down

0 comments on commit 1ab6034

Please sign in to comment.