socketry / nio4r

Cross-platform asynchronous I/O primitives for scalable network clients and servers.
Other
965 stars 86 forks source link

Fix conversion loses int precision #297

Closed tsimnujhawj closed 1 year ago

tsimnujhawj commented 1 year ago

For: https://github.com/socketry/nio4r/issues/298

compiling bytebuffer.c
bytebuffer.c:308:20: warning: implicit conversion loses integer precision: 'ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
    return INT2NUM(bytes_read);
           ~~~~~~~ ^~~~~~~~~~
bytebuffer.c:338:20: warning: implicit conversion loses integer precision: 'ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
    return INT2NUM(bytes_written);
           ~~~~~~~ ^~~~~~~~~~~~~

Getting this error on gem install nio4r using an Apple M1 computer with Ruby 3.0.6

The value of a long type is being assigned to an int type, which may result in the loss of data. By casting the bytes_read and bytes_written variable to an int type, this will ensure that the bytes_read and bytes_written value is truncated to fit in the range of an int type, and prevent any loss of data, which fixes this error.

Locally, I was able to install this gem on my Apple M1 with Ruby 3.0.6 with these changes.

I'm not a C programmer, so please scrutinize.

Types of Changes

Contribution