From: Wolfgang Bumiller Date: Sun, 23 Dec 2012 19:55:15 +0000 (+0100) Subject: Even safer vector macros X-Git-Tag: 0.2.1~1 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=11ffe6131450df1dbe3eaf1ac40cdee6e6f747db;p=xonotic%2Fgmqcc.git Even safer vector macros --- diff --git a/gmqcc.h b/gmqcc.h index b097188..ff2e9db 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -295,15 +295,15 @@ void _util_vec_grow(void **a, size_t i, size_t s); /* exposed interface */ #define vec_meta(A) (((vector_t*)(A)) - 1) #define vec_free(A) ((A) ? (mem_d((void*)vec_meta(A)), (A) = NULL) : 0) -#define vec_push(A,V) (GMQCC_VEC_WILLGROW(A,1), (A)[vec_meta(A)->used++] = (V)) +#define vec_push(A,V) (GMQCC_VEC_WILLGROW((A),1), (A)[vec_meta(A)->used++] = (V)) #define vec_size(A) ((A) ? vec_meta(A)->used : 0) -#define vec_add(A,N) (GMQCC_VEC_WILLGROW(A,N), vec_meta(A)->used += (N), &(A)[vec_meta(A)->used-(N)]) +#define vec_add(A,N) (GMQCC_VEC_WILLGROW((A),(N)), vec_meta(A)->used += (N), &(A)[vec_meta(A)->used-(N)]) #define vec_last(A) ((A)[vec_meta(A)->used - 1]) #define vec_pop(A) (vec_meta(A)->used -= 1) #define vec_shrinkto(A,N) (vec_meta(A)->used = (N)) #define vec_shrinkby(A,N) (vec_meta(A)->used -= (N)) -#define vec_append(A,N,S) memcpy(vec_add(A, N), (S), (N) * sizeof(*(S))) -#define vec_upload(X,Y,S) memcpy(vec_add(X, (S) * sizeof(*(Y))), (Y), (S) * sizeof(*(Y))) +#define vec_append(A,N,S) memcpy(vec_add((A), (N)), (S), (N) * sizeof(*(S))) +#define vec_upload(X,Y,S) memcpy(vec_add((X), (S) * sizeof(*(Y))), (Y), (S) * sizeof(*(Y))) #define vec_remove(A,I,N) memmove((A)+(I),(A)+((I)+(N)),sizeof(*(A))*(vec_meta(A)->used-(I)-(N))),vec_meta(A)->used-=(N) typedef struct hash_table_t {