commit 03f6bdb0d685dcfe322b7d68531cf278a48c1fe1
parent 0fcee3d02c7e6029f283664ed5c6382dfb77a2b4
Author: Christian Grothoff <christian@grothoff.org>
Date: Sun, 2 Aug 2026 22:36:21 +0200
static asserts must be first to avoid mixing decl and code
Diffstat:
7 files changed, 18 insertions(+), 15 deletions(-)
diff --git a/src/exchange/taler-exchange-httpd_post-melt.c b/src/exchange/taler-exchange-httpd_post-melt.c
@@ -420,6 +420,9 @@ phase_parse_request (
GNUNET_JSON_spec_end ()
};
+ /* validate array size */
+ GNUNET_static_assert (
+ TALER_MAX_COINS < INT_MAX / TALER_CNC_KAPPA);
res = TALER_MHD_parse_json_data (mc->rc->connection,
root,
spec);
@@ -432,10 +435,6 @@ phase_parse_request (
return;
}
- /* validate array size */
- GNUNET_static_assert (
- TALER_MAX_COINS < INT_MAX / TALER_CNC_KAPPA);
-
mc->request.refresh.num_coins = json_array_size (j_denoms_h);
if (0 == mc->request.refresh.num_coins)
{
@@ -1215,15 +1214,14 @@ phase_prepare_transaction (
for (size_t i = 0; i < num_cs_r_values; i++)
{
size_t idx = mc->request.cs_indices[i];
-
struct TALER_BlindedDenominationSignature *sig =
&mc->request.refresh.denom_sigs[idx];
uint64_t bit = sig->blinded_sig->details.blinded_cs_answer.b;
- mc->request.refresh.cs_r_choices |= bit << i;
GNUNET_static_assert (
TALER_MAX_COINS <=
sizeof(mc->request.refresh.cs_r_choices) * 8);
+ mc->request.refresh.cs_r_choices |= bit << i;
}
}
}
diff --git a/src/exchange/taler-exchange-httpd_post-withdraw.c b/src/exchange/taler-exchange-httpd_post-withdraw.c
@@ -679,16 +679,15 @@ phase_prepare_transaction (
for (size_t i = 0; i < num_cs_r_values; i++)
{
size_t idx = wc->request.cs_indices[i];
-
struct TALER_BlindedDenominationSignature *sig =
&wc->request.withdraw.denom_sigs[idx];
uint64_t bit = sig->blinded_sig->details.blinded_cs_answer.b;
- GNUNET_assert (bit <= 1); /* well, should actually be 0 or 1 */
- wc->request.withdraw.cs_r_choices |= bit << i;
GNUNET_static_assert (
TALER_MAX_COINS <=
sizeof(wc->request.withdraw.cs_r_choices) * 8);
+ GNUNET_assert (bit <= 1); /* well, should actually be 0 or 1 */
+ wc->request.withdraw.cs_r_choices |= bit << i;
}
}
wc->phase++;
diff --git a/src/include/platform.h b/src/include/platform.h
@@ -35,6 +35,12 @@
if it is available! */
#undef ENABLE_NLS
+#if HAVE_THREAD_LOCAL_GCC
+#define TALER_THREAD_LOCAL __thread
+#else
+#define TALER_THREAD_LOCAL
+#endif
+
#if (GNUNET_EXTRA_LOGGING >= 1)
#define VERBOSE(cmd) cmd
diff --git a/src/mhd/mhd_legal.c b/src/mhd/mhd_legal.c
@@ -227,7 +227,7 @@ TALER_MHD_reply_legal (struct MHD_Connection *conn,
/* Client expressed no preference between these two formats,
so fall back to our own ranking instead of letting the
last entry in the list win. */
- if ( (q == best_lang_q) &&
+ if ( (q <= best_lang_q) &&
(p->priority <= t->priority) )
continue;
}
diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c
@@ -56,12 +56,12 @@ qconv_amount_currency_tuple (void *cls,
const struct TALER_Amount *amount = data;
size_t sz;
+ GNUNET_static_assert (sizeof(uint32_t) == sizeof(Oid));
GNUNET_assert (NULL != db);
GNUNET_assert (NULL != amount);
GNUNET_assert (1 == param_length);
GNUNET_assert (1 <= scratch_length);
GNUNET_assert (sizeof (struct TALER_Amount) == data_len);
- GNUNET_static_assert (sizeof(uint32_t) == sizeof(Oid));
{
char *out;
Oid oid_v;
@@ -147,12 +147,12 @@ qconv_amount_tuple (void *cls,
const struct TALER_Amount *amount = data;
size_t sz;
+ GNUNET_static_assert (sizeof(uint32_t) == sizeof(Oid));
GNUNET_assert (NULL != db);
GNUNET_assert (NULL != amount);
GNUNET_assert (1 == param_length);
GNUNET_assert (1 <= scratch_length);
GNUNET_assert (sizeof (struct TALER_Amount) == data_len);
- GNUNET_static_assert (sizeof(uint32_t) == sizeof(Oid));
{
char *out;
Oid oid_v;
diff --git a/src/util/amount.c b/src/util/amount.c
@@ -950,7 +950,7 @@ const struct TALER_Amount *
TALER_amount_set_find (const char *currency,
const struct TALER_AmountSet *as)
{
- static struct TALER_Amount z;
+ static TALER_THREAD_LOCAL struct TALER_Amount z;
for (unsigned int i = 0; i<as->taa_size; i++)
{
diff --git a/src/util/payto.c b/src/util/payto.c
@@ -766,10 +766,10 @@ TALER_normalized_payto_hash (const struct TALER_NormalizedPayto npayto,
{
struct GNUNET_HashCode sha512;
+ GNUNET_static_assert (sizeof (sha512) > sizeof (*h_npayto));
GNUNET_CRYPTO_hash (npayto.normalized_payto,
strlen (npayto.normalized_payto) + 1,
&sha512);
- GNUNET_static_assert (sizeof (sha512) > sizeof (*h_npayto));
/* truncate */
GNUNET_memcpy (h_npayto,
&sha512,
@@ -787,10 +787,10 @@ TALER_full_payto_hash (const struct TALER_FullPayto fpayto,
{
struct GNUNET_HashCode sha512;
+ GNUNET_static_assert (sizeof (sha512) > sizeof (*h_fpayto));
GNUNET_CRYPTO_hash (fpayto.full_payto,
strlen (fpayto.full_payto) + 1,
&sha512);
- GNUNET_static_assert (sizeof (sha512) > sizeof (*h_fpayto));
/* truncate */
GNUNET_memcpy (h_fpayto,
&sha512,