[Mesa-dev] [PATCH] gallium/os: Use unsigned integers for size computation

Nicolai Hähnle nhaehnle at gmail.com
Wed Oct 12 11:07:10 UTC 2016


Specifically, the point is that size_t is for CPU sizes, while this code 
is about GPU sizes. The patch is

Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com>

On 11.10.2016 19:57, Axel Davy wrote:
> size_t could be uint32_t when compiling 32 bits.
>
> However that would lead to overflow, which was the initial reason of the
> patch
> 218459771a1801d7ad20dd340ac35a50f2b5b81a
>
> On 11/10/2016 19:43, Chuck Atkins wrote:
>> Shouldn't' the size argument itself be size_t instead of uint64_t?
>>
>> - Chuck
>>
>>
>> On Tue, Oct 11, 2016 at 12:59 PM, Axel Davy <axel.davy at ens.fr
>> <mailto:axel.davy at ens.fr>> wrote:
>>
>>     Use uint64_t instead of int64_t in the calculation,
>>     as the result is uint64_t.
>>
>>     Signed-off-by: Axel Davy <axel.davy at ens.fr <mailto:axel.davy at ens.fr>>
>>     ---
>>     This corrects the small mistake from
>>     218459771a1801d7ad20dd340ac35a50f2b5b81a
>>     as reported by Emil.
>>
>>      src/gallium/auxiliary/os/os_misc.c | 4 ++--
>>      1 file changed, 2 insertions(+), 2 deletions(-)
>>
>>     diff --git a/src/gallium/auxiliary/os/os_misc.c
>>     b/src/gallium/auxiliary/os/os_misc.c
>>     index a32a9e5..09d4400 100644
>>     --- a/src/gallium/auxiliary/os/os_misc.c
>>     +++ b/src/gallium/auxiliary/os/os_misc.c
>>     @@ -131,7 +131,7 @@ os_get_total_physical_memory(uint64_t *size)
>>         if (phys_pages <= 0 || page_size <= 0)
>>            return false;
>>
>>     -   *size = (int64_t)phys_pages * (int64_t)page_size;
>>     +   *size = (uint64_t)phys_pages * (uint64_t)page_size;
>>         return true;
>>      #elif defined(PIPE_OS_APPLE) || defined(PIPE_OS_BSD)
>>         size_t len = sizeof(*size);
>>     @@ -159,7 +159,7 @@ os_get_total_physical_memory(uint64_t *size)
>>         if (ret != B_OK || info.max_pages <= 0)
>>            return false;
>>
>>     -   *size = (int64_t)info.max_pages * (int64_t)B_PAGE_SIZE;
>>     +   *size = (uint64_t)info.max_pages * (uint64_t)B_PAGE_SIZE;
>>         return true;
>>      #elif defined(PIPE_OS_WINDOWS)
>>         MEMORYSTATUSEX status;
>>     --
>>     2.10.0
>>
>>     _______________________________________________
>>     mesa-dev mailing list
>>     mesa-dev at lists.freedesktop.org <mailto:mesa-dev at lists.freedesktop.org>
>>     https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>>     <https://lists.freedesktop.org/mailman/listinfo/mesa-dev>
>>
>>
>
>
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>


More information about the mesa-dev mailing list