On 23/12/14 01:02, Chad Versace wrote: > On 12/21/2014 09:00 AM, Emil Velikov wrote: >> On 16 December 2014 at 08:18, Chad Versace <[email protected]> >> wrote: >>> This is useful for making a writable copy of a read-only attribute list. >>> >>> Signed-off-by: Chad Versace <[email protected]> >>> --- >>> src/waffle/core/wcore_attrib_list.c | 19 +++++++++++++++++++ >>> src/waffle/core/wcore_attrib_list.h | 3 +++ >>> 2 files changed, 22 insertions(+) >>> >>> diff --git a/src/waffle/core/wcore_attrib_list.c >>> b/src/waffle/core/wcore_attrib_list.c >>> index a7f087d..94013b9 100644 >>> --- a/src/waffle/core/wcore_attrib_list.c >>> +++ b/src/waffle/core/wcore_attrib_list.c >>> @@ -28,6 +28,7 @@ >>> #include <stdbool.h> >>> #include <stdint.h> >>> #include <stddef.h> >>> +#include <string.h> >>> >>> size_t >>> wcore_attrib_list_length(const intptr_t attrib_list[]) >>> @@ -43,6 +44,24 @@ wcore_attrib_list_length(const intptr_t attrib_list[]) >>> return (i - attrib_list) / 2; >>> } >>> >>> +intptr_t* >>> +wcore_attrib_list_copy(const intptr_t attrib_list[]) >>> +{ >>> + intptr_t *copy; >>> + >>> + if (attrib_list) { >>> + size_t length = wcore_attrib_list_length(attrib_list); >>> + intptr_t size = (2 * length + 1) * sizeof(intptr_t); >>> + copy = malloc(size); >>> + memcpy(copy, attrib_list, size); >>> + } else { >>> + copy = malloc(sizeof(intptr_t)); >>> + copy[0] = 0; >>> + } >> We might want to add error checking after the malloc - to silence >> static analysers at the very least :-) > > Good idea. How about this? > > copy = malloc(size); > if (!copy) { > wcore_error(WAFFLE_ERROR_BAD_ALLOC); > return NULL; > } > Sounds good, and with that one in we might want to handle the NULL in waffle_window_create2() with patch 09.
Thanks for keeping with my nitpicks :-) -Emil _______________________________________________ waffle mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/waffle

