[vlc-devel] [PATCH v2 1/2] chromecast: fix _Write return type

Alexandre Janniaux ajanni at videolabs.io
Fri Jan 22 09:24:22 UTC 2021


Hi,

On Fri, Jan 22, 2021 at 07:46:58AM +0100, Steve Lhomme wrote:
> On 2021-01-21 12:58, Alexandre Janniaux wrote:
> > vlc_tls_Write returns a ssize_t.
> > ---
> >   modules/stream_out/chromecast/chromecast_communication.cpp | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/modules/stream_out/chromecast/chromecast_communication.cpp b/modules/stream_out/chromecast/chromecast_communication.cpp
> > index 347a15dbc6..217d7a0e56 100644
> > --- a/modules/stream_out/chromecast/chromecast_communication.cpp
> > +++ b/modules/stream_out/chromecast/chromecast_communication.cpp
> > @@ -449,9 +449,9 @@ int ChromecastCommunication::sendMessage( const castchannel::CastMessage &msg )
> >       SetDWBE(p_data, i_size);
> >       msg.SerializeWithCachedSizesToArray(p_data + PACKET_HEADER_LEN);
> > -    int i_ret = vlc_tls_Write(m_tls, p_data, PACKET_HEADER_LEN + i_size);
> > +    ssize_t i_ret = vlc_tls_Write(m_tls, p_data, PACKET_HEADER_LEN + i_size);
> >       delete[] p_data;
> > -    if (i_ret == PACKET_HEADER_LEN + i_size)
> > +    if (i_ret > 0 && i_ret == PACKET_HEADER_LEN + i_size)
>
> You don't need to check if i_ret is positive, since you only return success
> if the value is exactly the one requested. And as seen in the next patch,
> that value can never be negative (there is no check we are sending a
> negative buffer size).

Yes, but a negative ssize_t casted into size_t is positive.
It's very unlikely (certain) that it won't be the value
we're checking but casting a negative number into unsigned
is quite ugly and can be tricky in other cases, so keeping
it clear is preferable IMHO.

This patch doesn't cast yet, but it prepares for the changes
in the next one.

Regards,
--
Alexandre Janniaux
Videolabs

>
> >           return VLC_SUCCESS;
> >       msg_Warn( m_module, "failed to send message %s (%s)", msg.payload_utf8().c_str(), strerror( errno ) );
> > --
> > 2.30.0
> >
> > _______________________________________________
> > vlc-devel mailing list
> > To unsubscribe or modify your subscription options:
> > https://mailman.videolan.org/listinfo/vlc-devel
> >
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list