From fe61fe517f8e3359869f5ae37b0a921400aaaf05 Mon Sep 17 00:00:00 2001 From: Özgür Kesim Date: Sun, 30 Jul 2023 19:12:59 +0200 Subject: pq: aligment fixes and oid adjustments - aligment issues fixed in pq_result_helper.c - typname for string is "text" not "varchar" - compiler didn't like the function signature annotation `char *elements[static num]` NEWS: function-signature adjustment due to compiler error --- src/include/gnunet_pq_lib.h | 4 ++-- src/pq/pq_query_helper.c | 16 ++++++++++++---- src/pq/pq_result_helper.c | 2 +- src/pq/test_pq.c | 8 ++++---- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h index 65ba18b9b..7914a5c71 100644 --- a/src/include/gnunet_pq_lib.h +++ b/src/include/gnunet_pq_lib.h @@ -382,8 +382,8 @@ GNUNET_PQ_query_param_array_string ( struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_ptrs_string ( unsigned int num, - const char *elements[static num], - const struct GNUNET_PQ_Context *db); + const char *elements[], + struct GNUNET_PQ_Context *db); /** diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c index 2ffadbd75..cc24598e5 100644 --- a/src/pq/pq_query_helper.c +++ b/src/pq/pq_query_helper.c @@ -768,8 +768,11 @@ qconv_array ( for (unsigned int i = 0; i < num; i++) { size_t sz = same_sized ? meta->same_size : sizes[i]; + size_t hsz = htonl (sz); - *(uint32_t *) out = htonl (sz); + GNUNET_memcpy (out, + &hsz, + sizeof(hsz)); out += sizeof(uint32_t); switch (meta->typ) @@ -790,8 +793,13 @@ qconv_array ( } case array_of_uint32: { + uint32_t v; GNUNET_assert (sizeof(uint32_t) == sz); - *(uint32_t *) out = htonl (*(uint32_t *) in); + + v = htonl (*(uint32_t *) in); + GNUNET_memcpy (out, + &v, + sizeof(v)); in += sz; break; } @@ -1166,8 +1174,8 @@ GNUNET_PQ_query_param_array_string ( struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_ptrs_string ( unsigned int num, - const char *elements[static num], - const struct GNUNET_PQ_Context *db) + const char *elements[], + struct GNUNET_PQ_Context *db) { Oid oid; diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c index 4fca0e6cb..f230826cb 100644 --- a/src/pq/pq_result_helper.c +++ b/src/pq/pq_result_helper.c @@ -1697,7 +1697,7 @@ GNUNET_PQ_result_spec_array_string ( info->typ = array_of_string; GNUNET_assert (GNUNET_OK == GNUNET_PQ_get_oid_by_name (db, - "varchar", + "text", &info->oid)); struct GNUNET_PQ_ResultSpec res = { diff --git a/src/pq/test_pq.c b/src/pq/test_pq.c index a20ff9ddd..d70e18e6d 100644 --- a/src/pq/test_pq.c +++ b/src/pq/test_pq.c @@ -76,7 +76,7 @@ postgres_prepare (struct GNUNET_PQ_Context *db) ",arr_int4" ",arr_int8" ",arr_bytea" - ",arr_varchar" + ",arr_text" ",arr_abs_time" ",arr_rel_time" ",arr_timestamp" @@ -102,7 +102,7 @@ postgres_prepare (struct GNUNET_PQ_Context *db) ",arr_int4" ",arr_int8" ",arr_bytea" - ",arr_varchar" + ",arr_text" ",arr_abs_time" ",arr_rel_time" ",arr_timestamp" @@ -280,7 +280,7 @@ run_queries (struct GNUNET_PQ_Context *db) &sz_buf, &arr_buf), GNUNET_PQ_result_spec_array_string (db, - "arr_varchar", + "arr_text", &num_str, &arr_str), GNUNET_PQ_result_spec_end @@ -510,7 +510,7 @@ main (int argc, ",arr_int4 INT4[]" ",arr_int8 INT8[]" ",arr_bytea BYTEA[]" - ",arr_varchar VARCHAR[]" + ",arr_text TEXT[]" ",arr_abs_time INT8[]" ",arr_rel_time INT8[]" ",arr_timestamp INT8[]" -- cgit v1.2.3