From: Michael Wallner Date: Wed, 1 Feb 2017 12:50:49 +0000 (+0100) Subject: fix cppcheck warnings X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=ddeb4918bce67ed63c5f4c8c4e250e92ebdef89d;p=m6w6%2Fext-psi fix cppcheck warnings --- diff --git a/php_psi.h b/php_psi.h index 1609700..631c2a2 100644 --- a/php_psi.h +++ b/php_psi.h @@ -59,6 +59,9 @@ static inline psi_object *PSI_OBJ(zval *zv, zend_object *zo) { if (zv) { zo = Z_OBJ_P(zv); } + if (!zo) { + return NULL; + } return (void *) (((char *) zo) - zo->handlers->offset); } diff --git a/src/context.c b/src/context.c index 1090e98..b4e73ad 100644 --- a/src/context.c +++ b/src/context.c @@ -85,8 +85,8 @@ struct psi_context *psi_context_init(struct psi_context *C, struct psi_context_o ops->init(C); } - ZEND_ASSERT(ops->call != NULL); - ZEND_ASSERT(ops->compile != NULL); + assert(ops->call != NULL); + assert(ops->compile != NULL); /* build up predefs in a temporary PSI_Data for validation */ memset(&T, 0, sizeof(T)); diff --git a/src/libffi.c b/src/libffi.c index aea1cfa..e859dbd 100644 --- a/src/libffi.c +++ b/src/libffi.c @@ -69,7 +69,7 @@ static void *psi_ffi_closure_alloc(size_t s, void **code) static ffi_status psi_ffi_prep_closure(ffi_closure **closure, void **code, ffi_cif *sig, void (*handler)(ffi_cif*,void*,void**,void*), void *data) { *closure = psi_ffi_closure_alloc(sizeof(ffi_closure), code); - ZEND_ASSERT(*closure != NULL); + assert(*closure != NULL); #if PSI_HAVE_FFI_PREP_CLOSURE_LOC return ffi_prep_closure_loc(*closure, sig, handler, data, *code); @@ -102,7 +102,7 @@ static void psi_ffi_prep_va(ffi_cif *base, ffi_cif *signature, size_t argc, size rc = ffi_prep_cif(signature, base->abi, argc + va_count, base->rtype, param_types); #endif - ZEND_ASSERT(FFI_OK == rc); + assert(FFI_OK == rc); } static inline ffi_type *psi_ffi_decl_arg_type(struct psi_decl_arg *darg); @@ -175,7 +175,7 @@ static inline struct psi_ffi_call *psi_ffi_call_alloc(struct psi_context *C, str rc = ffi_prep_cif(&call->signature, psi_ffi_abi(decl->abi->convention), c, psi_ffi_decl_arg_type(decl->func), call->params); - ZEND_ASSERT(FFI_OK == rc); + assert(FFI_OK == rc); return call; } @@ -205,7 +205,7 @@ static inline void psi_ffi_call_free(struct psi_ffi_call *call) { static inline ffi_type *psi_ffi_token_type(token_t t) { switch (t) { default: - ZEND_ASSERT(0); + assert(0); /* no break */ case PSI_T_VOID: return &ffi_type_void; @@ -289,7 +289,7 @@ static size_t psi_ffi_struct_type_pad(ffi_type **els, size_t padding) { static ffi_type **psi_ffi_struct_type_elements(struct psi_decl_struct *strct) { size_t i = 0, argc = psi_plist_count(strct->args), nels = 0, offset = 0, maxalign = 0; - ffi_type **els = calloc(argc + 1, sizeof(*els)); + ffi_type **tmp, **els = calloc(argc + 1, sizeof(*els)); struct psi_decl_arg *darg; while (psi_plist_get(strct->args, i++, &darg)) { @@ -306,7 +306,13 @@ static ffi_type **psi_ffi_struct_type_elements(struct psi_decl_struct *strct) { if ((padding = psi_offset_padding(darg->layout->pos - offset, type->alignment))) { if (nels + padding + 1 > argc) { argc += padding; - els = realloc(els, (argc + 1) * sizeof(*els)); + tmp = realloc(els, (argc + 1) * sizeof(*els)); + if (tmp) { + els = tmp; + } else { + free(els); + return NULL; + } els[argc] = NULL; } psi_ffi_struct_type_pad(&els[nels], padding); @@ -378,7 +384,7 @@ static inline struct psi_ffi_context *psi_ffi_context_init(struct psi_ffi_contex L->params[0] = &ffi_type_pointer; L->params[1] = &ffi_type_pointer; rc = ffi_prep_cif(&L->signature, FFI_DEFAULT_ABI, 2, &ffi_type_void, L->params); - ZEND_ASSERT(rc == FFI_OK); + assert(rc == FFI_OK); return L; } diff --git a/src/libjit.c b/src/libjit.c index da8f25e..338e8a7 100644 --- a/src/libjit.c +++ b/src/libjit.c @@ -42,7 +42,7 @@ static inline jit_type_t psi_jit_token_type(token_t t) { switch (t) { default: - ZEND_ASSERT(0); + assert(0); /* no break */ case PSI_T_VOID: return jit_type_void; @@ -155,7 +155,7 @@ static unsigned psi_jit_struct_type_elements(struct psi_decl_struct *strct, /* apply struct alignment padding */ offset = (offset + maxalign - 1) & ~(maxalign - 1); - ZEND_ASSERT(offset <= strct->size); + assert(offset <= strct->size); if (offset < strct->size) { nels += psi_jit_struct_type_pad(&(*fields)[nels], strct->size - offset); } @@ -517,7 +517,7 @@ static void psi_jit_call_va(struct psi_context *C, struct psi_call_frame *frame, signature = jit_type_create_signature(jit_abi_vararg, jit_type_get_return(info->signature), param_types, argc + va_count, 1); - ZEND_ASSERT(signature); + assert(signature); info->impl.fn.frame = frame; jit_apply(signature, decl->sym, args, argc, rval); diff --git a/src/marshal.c b/src/marshal.c index 61bd4e9..c771e79 100644 --- a/src/marshal.c +++ b/src/marshal.c @@ -400,8 +400,6 @@ impl_val *psi_let_strval(impl_val *tmp, struct psi_decl_type *spec, token_t impl } else { tmp->ptr = ""; } - } else if (0 && Z_TYPE_P(zvalue) == IS_STRING) { - tmp->ptr = Z_STRVAL_P(zvalue); } else { zend_string *zs = zval_get_string(zvalue); tmp->ptr = estrdup(zs->val); diff --git a/src/types.h b/src/types.h index 17c0719..1a729f9 100644 --- a/src/types.h +++ b/src/types.h @@ -94,7 +94,8 @@ static inline impl_val *enref_impl_val(void *ptr, struct psi_decl_var *var) { return ptr; } - val = val_ptr = calloc(var->pointer_level + 1, sizeof(void *)); + val = calloc(var->pointer_level + 1, sizeof(void *)); + val_ptr = val; for (i = !var->arg->var->array_size; i < var->pointer_level; ++i) { #if 0 fprintf(stderr, "++\n"); diff --git a/src/types/decl_enum.c b/src/types/decl_enum.c index 85ce187..026c375 100644 --- a/src/types/decl_enum.c +++ b/src/types/decl_enum.c @@ -58,15 +58,13 @@ void psi_decl_enum_dump(int fd, struct psi_decl_enum *e, unsigned level) size_t i = 0; struct psi_decl_enum_item *item; - ++level; while (psi_plist_get(e->items, i++, &item)) { if (i > 1) { dprintf(fd, ",\n"); } - dprintf(fd, "%s", psi_t_indent(level)); + dprintf(fd, "%s", psi_t_indent(level + 1)); psi_decl_enum_item_dump(fd, item); } - --level; } dprintf(fd, "\n}"); } diff --git a/src/types/set_exp.c b/src/types/set_exp.c index 27ed030..4ae7a45 100644 --- a/src/types/set_exp.c +++ b/src/types/set_exp.c @@ -50,7 +50,7 @@ struct psi_set_exp *psi_set_exp_init(enum psi_set_exp_kind kind, void *data) void psi_set_exp_exec(struct psi_set_exp *val, struct psi_call_frame *frame) { - struct psi_call_frame_symbol *frame_sym = NULL; + struct psi_call_frame_symbol *frame_sym; struct psi_call_frame_argument *frame_arg; struct psi_decl_var *set_dvar = psi_set_exp_get_decl_var(val); struct psi_impl_var *set_ivar = psi_set_exp_get_impl_var(val); diff --git a/src/types/set_func.c b/src/types/set_func.c index fff7c88..7e56637 100644 --- a/src/types/set_func.c +++ b/src/types/set_func.c @@ -164,7 +164,8 @@ static inline bool psi_set_func_validate_to_array(struct psi_data *data, return true; default: - complex: switch (psi_decl_type_get_real(set_var->arg->type)->type) { + complex: + switch (psi_decl_type_get_real(set_var->arg->type)->type) { case PSI_T_UNION: case PSI_T_STRUCT: break; @@ -185,8 +186,8 @@ static inline bool psi_set_func_validate_to_recursive(struct psi_data *data, struct psi_impl *impl) { if (!set->outer - || set->outer->kind - != PSI_SET_FUNC|| set->outer->data.func->type != PSI_T_TO_ARRAY) { + || set->outer->kind != PSI_SET_FUNC + || set->outer->data.func->type != PSI_T_TO_ARRAY) { data->error(data, func->token, PSI_WARNING, "Expected to_array() as parent to recursion in `set` statement" " of implementation '%s'", @@ -273,12 +274,6 @@ bool psi_set_func_validate(struct psi_data *data, struct psi_set_func *func, return false; } break; - case PSI_T_ELLIPSIS: - abort(); - if (!psi_set_func_validate_to_recursive(data, func, set, impl)) { - return false; - } - break; default: data->error(data, func->token, PSI_WARNING, "Unknown cast '%s' in `set` statement of implementation '%s'",