[libcamera-devel] v4l2: v4l2_camera_proxy: Fix sign compare compilation error

Message ID 20200307212530.28053-1-laurent.pinchart@ideasonboard.com
State Accepted
Commit 1268751ce6d170dc1aa968f1314c0bb5852b1b8e
Headers show
Series
  • [libcamera-devel] v4l2: v4l2_camera_proxy: Fix sign compare compilation error
Related show

Commit Message

Laurent Pinchart March 7, 2020, 9:25 p.m. UTC
When compiling for ARM and uClibc, gcc-8.3.0 complains about comparison
of integer expressions of different signedness:

../../src/v4l2/v4l2_camera_proxy.cpp: In member function ‘void* V4L2CameraProxy::mmap(void*, size_t, int, int, off_t)’:
../../src/v4l2/v4l2_camera_proxy.cpp:88:25: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘off_t’ {aka ‘long int’} [-Werror=sign-compare]
  if (index * sizeimage_ != offset || length != sizeimage_) {
      ~~~~~~~~~~~~~~~~~~~^~~~~~~~~

Fix the compilation error with a cast.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/v4l2/v4l2_camera_proxy.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Niklas Söderlund March 8, 2020, 4:37 p.m. UTC | #1
Hi Laurent,

Thanks for your work.

On 2020-03-07 23:25:28 +0200, Laurent Pinchart wrote:
> When compiling for ARM and uClibc, gcc-8.3.0 complains about comparison
> of integer expressions of different signedness:
> 
> ../../src/v4l2/v4l2_camera_proxy.cpp: In member function ‘void* V4L2CameraProxy::mmap(void*, size_t, int, int, off_t)’:
> ../../src/v4l2/v4l2_camera_proxy.cpp:88:25: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘off_t’ {aka ‘long int’} [-Werror=sign-compare]
>   if (index * sizeimage_ != offset || length != sizeimage_) {
>       ~~~~~~~~~~~~~~~~~~~^~~~~~~~~
> 
> Fix the compilation error with a cast.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

> ---
>  src/v4l2/v4l2_camera_proxy.cpp | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp
> index 622520479be0..b620f236499c 100644
> --- a/src/v4l2/v4l2_camera_proxy.cpp
> +++ b/src/v4l2/v4l2_camera_proxy.cpp
> @@ -85,7 +85,8 @@ void *V4L2CameraProxy::mmap(void *addr, size_t length, int prot, int flags,
>  	}
>  
>  	unsigned int index = offset / sizeimage_;
> -	if (index * sizeimage_ != offset || length != sizeimage_) {
> +	if (static_cast<off_t>(index * sizeimage_) != offset ||
> +	    length != sizeimage_) {
>  		errno = EINVAL;
>  		return MAP_FAILED;
>  	}
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch

diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp
index 622520479be0..b620f236499c 100644
--- a/src/v4l2/v4l2_camera_proxy.cpp
+++ b/src/v4l2/v4l2_camera_proxy.cpp
@@ -85,7 +85,8 @@  void *V4L2CameraProxy::mmap(void *addr, size_t length, int prot, int flags,
 	}
 
 	unsigned int index = offset / sizeimage_;
-	if (index * sizeimage_ != offset || length != sizeimage_) {
+	if (static_cast<off_t>(index * sizeimage_) != offset ||
+	    length != sizeimage_) {
 		errno = EINVAL;
 		return MAP_FAILED;
 	}