On 11/04/15 14:55, Diego Biurrun wrote:
> On Sat, Apr 11, 2015 at 02:45:56PM +0200, Anton Khirnov wrote:
>> Quoting Diego Biurrun (2015-04-11 11:00:51)
>>> On Sat, Apr 11, 2015 at 02:11:06AM +0530, Himangi Saraogi wrote:
>>>> --- a/libavformat/rtmppkt.c
>>>> +++ b/libavformat/rtmppkt.c
>>>> @@ -538,7 +538,8 @@ static const char* rtmp_packet_type(int type)
>>>>  static void amf_tag_contents(void *ctx, const uint8_t *data,
>>>>                               const uint8_t *data_end)
>>>>  {
>>>> -    unsigned int size, nb = -1;
>>>> +    unsigned int size;
>>>> +    uint32_t nb = UINT32_MAX;
>>>
>>> This is not correct, nb is assigned the return value from
>>> bystream_get_be32(), which is unsigned int.
>>
>> Stab. bytestream_get_be32 will obviously be at most 32bit.
> 
> Stab back.  It returns unsigned int, so that's the proper type for
> variables capturing its return (type).  Yes, one could argue that
> it should return uint32_t instead.
> 

Uff, -1 is assigned to an unsigned variable in 2 situations:

- Set a value outside the working range
- Set a value to 0xfff..ff and then use in mask/shift operations.

It works as expected but the compiler will warn you to make sure it is
what you want.

To suppress it you can do the following:

- cast, it should make at least apparent to the reader that the code is
written on purpose (some compilers would still warn you).

- if you need a value outside your working range then UINT_MAX and
friends might good.

- if you need a value that's just a mask of 1 then might more
descriptive to express it using the 0xff..ff and possibly use a fixed
size type.

That said, would be nice if this discussion happens on irc instead since
the ml is not exactly great for continuous back and forth.

lu
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to