Patchwork fwts_mmap: fwts_page_size fix comparing size_t against -1

login
register
mail settings
Submitter Colin King
Date Oct. 25, 2012, 10:27 a.m.
Message ID <1351160862-29463-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/194107/
State Accepted
Headers show

Comments

Colin King - Oct. 25, 2012, 10:27 a.m.
From: Colin Ian King <colin.king@canonical.com>

sysconf returns a long and we need to compare this to -1
rather than a size_t (which is always positive).

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_mmap.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Alex Hung - Oct. 29, 2012, 6:18 a.m.
On 10/25/2012 06:27 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> sysconf returns a long and we need to compare this to -1
> rather than a size_t (which is always positive).
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_mmap.c |    4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/src/lib/src/fwts_mmap.c b/src/lib/src/fwts_mmap.c
> index c5acd26..58ab973 100644
> --- a/src/lib/src/fwts_mmap.c
> +++ b/src/lib/src/fwts_mmap.c
> @@ -33,12 +33,12 @@
>    */
>   size_t fwts_page_size(void)
>   {
> -	size_t page_size;
> +	long page_size;
>
>   	page_size = sysconf(_SC_PAGESIZE);
>
>   	/* If sysconf() returns -1, default it 4K */
> -	return page_size == -1 ? FWTS_DEFAULT_PAGE_SIZE : page_size;
> +	return (size_t)(page_size == -1 ? FWTS_DEFAULT_PAGE_SIZE : page_size);
>   }
>
>   /*
>
Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu - Oct. 29, 2012, 5:34 p.m.
On 10/25/2012 06:27 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> sysconf returns a long and we need to compare this to -1
> rather than a size_t (which is always positive).
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_mmap.c |    4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/src/lib/src/fwts_mmap.c b/src/lib/src/fwts_mmap.c
> index c5acd26..58ab973 100644
> --- a/src/lib/src/fwts_mmap.c
> +++ b/src/lib/src/fwts_mmap.c
> @@ -33,12 +33,12 @@
>    */
>   size_t fwts_page_size(void)
>   {
> -	size_t page_size;
> +	long page_size;
>
>   	page_size = sysconf(_SC_PAGESIZE);
>
>   	/* If sysconf() returns -1, default it 4K */
> -	return page_size == -1 ? FWTS_DEFAULT_PAGE_SIZE : page_size;
> +	return (size_t)(page_size == -1 ? FWTS_DEFAULT_PAGE_SIZE : page_size);
>   }
>
>   /*
>

Acked-by: Ivan Hu <ivan.hu@canonical.com>

Patch

diff --git a/src/lib/src/fwts_mmap.c b/src/lib/src/fwts_mmap.c
index c5acd26..58ab973 100644
--- a/src/lib/src/fwts_mmap.c
+++ b/src/lib/src/fwts_mmap.c
@@ -33,12 +33,12 @@ 
  */
 size_t fwts_page_size(void)
 {
-	size_t page_size;
+	long page_size;
 
 	page_size = sysconf(_SC_PAGESIZE);
 
 	/* If sysconf() returns -1, default it 4K */
-	return page_size == -1 ? FWTS_DEFAULT_PAGE_SIZE : page_size;
+	return (size_t)(page_size == -1 ? FWTS_DEFAULT_PAGE_SIZE : page_size);
 }
 
 /*