Re: [igt-dev] [PATCH i-g-t 09/21] lib/igt_kms: Make igt_display_init require at least one plane

Robert Foss
2019-01-16T17:11:24Z

Reviewed-by: Robert Foss <robert.foss@collabora.com>

On 1/16/19 12:20 PM, Petri Latvala wrote:
> Not only will the following calloc call end up allocating 0 bytes
> (undefined behaviour), but last_plane becomes (uint8_t)-1.
>
> Signed-off-by: Petri Latvala <petri.latvala@intel.com>
> Cc: Robert Foss <robert.foss@collabora.com>
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> ---
> lib/igt_kms.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/igt_kms.c b/lib/igt_kms.c
> index f926eafb..b06acb2b 100644
> --- a/lib/igt_kms.c
> +++ b/lib/igt_kms.c
> @@ -1932,7 +1932,7 @@ void igt_display_require(igt_display_t *display, int drm_fd)
> drmModeFreePlane(drm_plane);
> }
>
> - igt_assert_lte(0, n_planes);
> + igt_assert_lt(0, n_planes);
> pipe->planes = calloc(sizeof(igt_plane_t), n_planes);
> igt_assert_f(pipe->planes, "Failed to allocate memory for %d planes\n", n_planes);
> last_plane = n_planes - 1;
>