From b188f0557911ddb353f8b78d6770ba9fd0114329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Sun, 13 Jun 2021 07:06:14 +0800 Subject: Just use memset instead of a special init function --- catalog.c | 2 +- icclient/product.h | 3 +-- ord.c | 2 +- product.c | 15 --------------- 4 files changed, 3 insertions(+), 19 deletions(-) diff --git a/catalog.c b/catalog.c index caaef04..92dce73 100644 --- a/catalog.c +++ b/catalog.c @@ -41,7 +41,7 @@ size_t icclient_catalog_results(void *data, size_t size, size_t nmemb, void *use for (size_t i = 0; i < length; i++) { catalog->products[i] = malloc(sizeof(struct icclient_product)); struct icclient_product *product = catalog->products[i]; - icclient_product_init(product); + memset(product, '\0', sizeof(struct icclient_product)); json_object *object = json_object_array_get_idx(products, i); struct json_object_iterator iterator = json_object_iter_begin(object); struct json_object_iterator iterator_end = json_object_iter_end(object); diff --git a/icclient/product.h b/icclient/product.h index c3e91bd..8fa6bc3 100644 --- a/icclient/product.h +++ b/icclient/product.h @@ -23,11 +23,10 @@ struct icclient_product { extern "C" { #endif - void icclient_product_init(struct icclient_product *product); void icclient_product_free(struct icclient_product *product); #ifdef __cplusplus } #endif -#endif // ICCLIENT_PRODUCT_H +#endif diff --git a/ord.c b/ord.c index 18e1bd2..07e6e64 100644 --- a/ord.c +++ b/ord.c @@ -36,7 +36,7 @@ void icclient_ord_order(const char *sku, const icclient_catalog *catalog, icclient_product **products = ((icclient_catalog *)catalog)->products; qsort(products, catalog->length, sizeof(icclient_product *), prodcmp); icclient_product *key_product = malloc(sizeof(icclient_product)); - icclient_product_init(key_product); + memset(key_product, '\0', sizeof(icclient_product)); key_product->sku = malloc(strlen(sku) + 1); strcpy(key_product->sku, sku); icclient_product *product = *(icclient_product **)bsearch(&key_product diff --git a/product.c b/product.c index fcb16be..0323192 100644 --- a/product.c +++ b/product.c @@ -1,20 +1,6 @@ #include #include "icclient/product.h" -void icclient_product_init(struct icclient_product *product) -{ - product->sku = NULL; - product->description = NULL; - product->comment = NULL; - product->thumb = NULL; - product->image = NULL; - product->price = .0; - product->prod_group = NULL; - product->weight = .0; - product->author = NULL; - product->crosssell = NULL; -} - void icclient_product_free(struct icclient_product *product) { if (product->crosssell) @@ -34,5 +20,4 @@ void icclient_product_free(struct icclient_product *product) free(product->description); free(product->sku); free(product); - product = NULL; } -- cgit v1.2.3