X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fegl%2Fmain%2Feglarray.c;h=ba6cb3e6a4e7b683fc9f39475c8fd02387860e8f;hb=e5a7ef0013cfd0d9514a04d2be1186b7d41532b7;hp=3ccc8a649f0e545bacb53ddbe4f5b63eb9c98401;hpb=4683529048ee133481b2d8f1cae1685aa1736f9a;p=mesa.git diff --git a/src/egl/main/eglarray.c b/src/egl/main/eglarray.c index 3ccc8a649f0..ba6cb3e6a4e 100644 --- a/src/egl/main/eglarray.c +++ b/src/egl/main/eglarray.c @@ -26,6 +26,7 @@ **************************************************************************/ +#include #include #include @@ -157,25 +158,15 @@ _eglFilterArray(_EGLArray *array, void **data, EGLint size, if (!array) return 0; - if (filter) { - for (i = 0; i < array->Size; i++) { - if (filter(array->Elements[i], filter_data)) { - if (data && count < size) - data[count] = array->Elements[i]; - count++; - } - if (data && count >= size) - break; - } - } - else { - if (data) { - count = (size < array->Size) ? size : array->Size; - memcpy(data, array->Elements, count * sizeof(array->Elements[0])); - } - else { - count = array->Size; + assert(filter); + for (i = 0; i < array->Size; i++) { + if (filter(array->Elements[i], filter_data)) { + if (data && count < size) + data[count] = array->Elements[i]; + count++; } + if (data && count >= size) + break; } return count; @@ -197,6 +188,9 @@ _eglFlattenArray(_EGLArray *array, void *buffer, EGLint elem_size, EGLint size, count = array->Size; if (buffer) { + /* clamp size to 0 */ + if (size < 0) + size = 0; /* do not exceed buffer size */ if (count > size) count = size;