RE: [PATCH 09/11] staging: comedi: comedi_buf: clarify comedi_buf_read_alloc()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wednesday, January 02, 2013 12:03 PM, Ian Abbott wrote:
> On 02/01/2013 18:10, H Hartley Sweeten wrote:
>> Will the munge_count always be larger, or equal, to the buf_read_alloc_count?
>> The original code had the (int) cast so I wasn't sure. If so, then yes the variable
>> should be an unsigned int.
>
> Well the value it is being compared to (nbytes) is an unsigned int, so 
> the int value (available) will be converted to unsigned int before the 
> comparison anyway.  So making 'available' an unsigned int to begin with 
> shouldn't break anything that isn't already broke!

Not so. Simple test:


#include <stdio.h>
#include <stdlib.h>

int main(int argv, char *argc[])
{
        unsigned int var1;
        int var2;

        var1 = 1000;
        if (99 > var1)
                printf("1. 99 > %d\n", var1);

        var1 = -40;
        if (99 > var1)
                printf("2. 99 > %d\n", var1);

        var2 = 1000;
        if (99 > var2)
                printf("3. 99 > %d\n", var2);

        var2 = -40;
        if (99 > var2)
                printf("4. 99 > %d\n", var2);

        return 0;
}

$ ./a.out 
4. 99 > -40

Regards,
Hartley

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel


[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux