From: Emil Velikov Date: Thu, 16 May 2019 17:01:33 +0000 (+0100) Subject: egl: flesh out a _eglNumAttribs() helper X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=72b9aa973b010a6be95b5f955c658113016a36f5;p=mesa.git egl: flesh out a _eglNumAttribs() helper Reviewed-by: Mathias Fröhlich Reviewed-by: Marek Olšák Signed-off-by: Emil Velikov Signed-off-by: Marek Olšák --- diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index 61a3220705d..fb26c8a0888 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -340,22 +340,16 @@ _eglConvertIntsToAttribs(const EGLint *int_list, EGLAttrib **out_attrib_list) static EGLint * _eglConvertAttribsToInt(const EGLAttrib *attr_list) { + size_t size = _eglNumAttribs(attr_list); EGLint *int_attribs = NULL; /* Convert attributes from EGLAttrib[] to EGLint[] */ - if (attr_list) { - int i, size = 0; - - while (attr_list[size] != EGL_NONE) - size += 2; - - size += 1; /* add space for EGL_NONE */ - + if (size) { int_attribs = calloc(size, sizeof(int_attribs[0])); if (!int_attribs) return NULL; - for (i = 0; i < size; i++) + for (size_t i = 0; i < size; i++) int_attribs[i] = attr_list[i]; } return int_attribs; diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index cfd0ff66d64..f37b633b466 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -274,6 +274,19 @@ _eglIsResourceLinked(_EGLResource *res) return res->IsLinked; } +static inline size_t +_eglNumAttribs(const EGLAttrib *attribs) +{ + size_t len = 0; + + if (attribs) { + while (attribs[len] != EGL_NONE) + len += 2; + len++; + } + return len; +} + #ifdef HAVE_X11_PLATFORM _EGLDisplay* _eglGetX11Display(Display *native_display, const EGLAttrib *attrib_list);