summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Foad <jay.foad@gmail.com>2018-01-27 09:13:17 +0100
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2018-01-27 09:15:50 +0100
commit9e0ddfb5ef2acf4a70d0ece0f72fc474a63638fc (patch)
treed0b57f466f4e8a3291821d0928afe18ab3dc7f5e
parent4038e69c87af19d2ebf6eada5ee4c957269373fb (diff)
downloadgnutls-9e0ddfb5ef2acf4a70d0ece0f72fc474a63638fc.tar.gz
Inline version macros into its users.
This fixes a problem in _gnutls_version_is_supported() where we want to use preprocessing directives in the loop body. Doing this within a macro argument is undefined behaviour according to the C standard, and not supported by the system compiler on AIX. Signed-off-by: Jay Foad <jay.foad@gmail.com> Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
-rw-r--r--lib/algorithms/protocols.c42
1 files changed, 22 insertions, 20 deletions
diff --git a/lib/algorithms/protocols.c b/lib/algorithms/protocols.c
index 14204f0803..a70c3e5815 100644
--- a/lib/algorithms/protocols.c
+++ b/lib/algorithms/protocols.c
@@ -128,16 +128,13 @@ static const version_entry_st sup_versions[] = {
{0, 0, 0, 0, 0}
};
-#define GNUTLS_VERSION_LOOP(b) \
- const version_entry_st *p; \
- for(p = sup_versions; p->name != NULL; p++) { b ; }
-
-#define GNUTLS_VERSION_ALG_LOOP(a) \
- GNUTLS_VERSION_LOOP( if(p->id == version) { a; break; })
-
const version_entry_st *version_to_entry(gnutls_protocol_t version)
{
- GNUTLS_VERSION_ALG_LOOP(return p);
+ const version_entry_st *p;
+
+ for (p = sup_versions; p->name != NULL; p++)
+ if (p->id == version)
+ return p;
return NULL;
}
@@ -270,11 +267,12 @@ unsigned _gnutls_version_is_too_high(gnutls_session_t session, uint8_t major, ui
**/
const char *gnutls_protocol_get_name(gnutls_protocol_t version)
{
- const char *ret = NULL;
-
+ const version_entry_st *p;
/* avoid prefix */
- GNUTLS_VERSION_ALG_LOOP(ret = p->name);
- return ret;
+ for (p = sup_versions; p->name != NULL; p++)
+ if (p->id == version)
+ return p->name;
+ return NULL;
}
/**
@@ -288,14 +286,15 @@ const char *gnutls_protocol_get_name(gnutls_protocol_t version)
**/
gnutls_protocol_t gnutls_protocol_get_id(const char *name)
{
+ const version_entry_st *p;
gnutls_protocol_t ret = GNUTLS_VERSION_UNKNOWN;
- GNUTLS_VERSION_LOOP(
+ for (p = sup_versions; p->name != NULL; p++) {
if (strcasecmp(p->name, name) == 0) {
ret = p->id;
break;
}
- );
+ }
return ret;
}
@@ -313,12 +312,14 @@ gnutls_protocol_t gnutls_protocol_get_id(const char *name)
**/
const gnutls_protocol_t *gnutls_protocol_list(void)
{
+ const version_entry_st *p;
static gnutls_protocol_t supported_protocols[MAX_ALGOS] = { 0 };
if (supported_protocols[0] == 0) {
int i = 0;
- GNUTLS_VERSION_LOOP(supported_protocols[i++] = p->id);
+ for (p = sup_versions; p->name != NULL; p++)
+ supported_protocols[i++] = p->id;
supported_protocols[i++] = 0;
}
@@ -329,12 +330,12 @@ const gnutls_protocol_t *gnutls_protocol_list(void)
*/
gnutls_protocol_t _gnutls_version_get(uint8_t major, uint8_t minor)
{
+ const version_entry_st *p;
int ret = GNUTLS_VERSION_UNKNOWN;
- GNUTLS_VERSION_LOOP(
+ for (p = sup_versions; p->name != NULL; p++)
if ((p->major == major) && (p->minor == minor))
- ret = p->id
- );
+ ret = p->id;
return ret;
}
@@ -344,9 +345,10 @@ int
_gnutls_version_is_supported(gnutls_session_t session,
const gnutls_protocol_t version)
{
+ const version_entry_st *p;
int ret = 0;
- GNUTLS_VERSION_LOOP(
+ for (p = sup_versions; p->name != NULL; p++) {
if(p->id == version) {
#ifndef ENABLE_SSL3
if (p->obsolete != 0) return 0;
@@ -354,7 +356,7 @@ _gnutls_version_is_supported(gnutls_session_t session,
ret = p->supported && p->transport == session->internals.transport;
break;
}
- )
+ }
if (ret == 0)
return 0;