Skip to content

Commit 7fd6414

Browse files
mrdeep1obgm
authored andcommitted
tests: Fix compiler clash over index usage in test suites
Some compilers complain that index is already defined in <strings.h>. Replace index with lindex. Signed-off-by: Jon Shallow <supjps-libcoap@jpshallow.com>
1 parent d055d8d commit 7fd6414

3 files changed

Lines changed: 25 additions & 25 deletions

File tree

tests/dtls-client.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,16 @@ get_user_parameters(struct dtls_context_t *ctx,
239239
(void) session;
240240
user_parameters->force_extended_master_secret = force_extended_master_secret;
241241
if (ciphers) {
242-
int index = 0;
243-
while (index < DTLS_MAX_CIPHER_SUITES) {
244-
user_parameters->cipher_suites[index] = ciphers[index];
245-
if (ciphers[index] == TLS_NULL_WITH_NULL_NULL) {
242+
int i = 0;
243+
while (i < DTLS_MAX_CIPHER_SUITES) {
244+
user_parameters->cipher_suites[i] = ciphers[i];
245+
if (ciphers[i] == TLS_NULL_WITH_NULL_NULL) {
246246
break;
247247
}
248-
++index;
248+
++i;
249249
}
250-
if (index == DTLS_MAX_CIPHER_SUITES) {
251-
user_parameters->cipher_suites[index] = TLS_NULL_WITH_NULL_NULL;
250+
if (i == DTLS_MAX_CIPHER_SUITES) {
251+
user_parameters->cipher_suites[i] = TLS_NULL_WITH_NULL_NULL;
252252
}
253253
}
254254
}

tests/dtls-server.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,16 @@ get_user_parameters(struct dtls_context_t *ctx,
200200
(void) session;
201201
user_parameters->force_extended_master_secret = force_extended_master_secret;
202202
if (ciphers) {
203-
int index = 0;
204-
while (index < DTLS_MAX_CIPHER_SUITES) {
205-
user_parameters->cipher_suites[index] = ciphers[index];
206-
if (ciphers[index] == TLS_NULL_WITH_NULL_NULL) {
203+
int i = 0;
204+
while (i < DTLS_MAX_CIPHER_SUITES) {
205+
user_parameters->cipher_suites[i] = ciphers[i];
206+
if (ciphers[i] == TLS_NULL_WITH_NULL_NULL) {
207207
break;
208208
}
209-
++index;
209+
++i;
210210
}
211-
if (index == DTLS_MAX_CIPHER_SUITES) {
212-
user_parameters->cipher_suites[index] = TLS_NULL_WITH_NULL_NULL;
211+
if (i == DTLS_MAX_CIPHER_SUITES) {
212+
user_parameters->cipher_suites[i] = TLS_NULL_WITH_NULL_NULL;
213213
}
214214
}
215215
}

tests/dtls_ciphers_util.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ static dtls_cipher_t ciphers_table[ARRAY_LENGTH] = { TLS_NULL_WITH_NULL_NULL };
4444
static dtls_cipher_t find_cipher_suite(const char *arg) {
4545
if (arg) {
4646
size_t arg_len = strlen(arg);
47-
for (size_t index=0; index < ARRAY_LENGTH - 1; ++index) {
48-
size_t len = strlen(map[index].name);
47+
for (size_t i=0; i < ARRAY_LENGTH - 1; ++i) {
48+
size_t len = strlen(map[i].name);
4949
if (len <= arg_len) {
50-
if (strncmp(arg, map[index].name, len) == 0 && (arg[len] == 0 || arg[len] == SEP)) {
51-
return map[index].cipher;
50+
if (strncmp(arg, map[i].name, len) == 0 && (arg[len] == 0 || arg[len] == SEP)) {
51+
return map[i].cipher;
5252
}
5353
}
5454
}
@@ -57,13 +57,13 @@ static dtls_cipher_t find_cipher_suite(const char *arg) {
5757
}
5858

5959
static void add_cipher_suite(dtls_cipher_t cipher) {
60-
for (size_t index=0; index < ARRAY_LENGTH - 1; ++index) {
61-
if (ciphers_table[index] == cipher) {
60+
for (size_t i=0; i < ARRAY_LENGTH - 1; ++i) {
61+
if (ciphers_table[i] == cipher) {
6262
return;
6363
}
64-
if (ciphers_table[index] == TLS_NULL_WITH_NULL_NULL) {
65-
ciphers_table[index] = cipher;
66-
ciphers_table[index + 1] = TLS_NULL_WITH_NULL_NULL;
64+
if (ciphers_table[i] == TLS_NULL_WITH_NULL_NULL) {
65+
ciphers_table[i] = cipher;
66+
ciphers_table[i + 1] = TLS_NULL_WITH_NULL_NULL;
6767
return;
6868
}
6969
}
@@ -88,8 +88,8 @@ void
8888
cipher_suites_usage(FILE* file, const char* head) {
8989
fprintf(file, "%s-c ciphers\tlist of cipher suites separated by ':'\n", head);
9090
fprintf(file, "%s\t\t(default is %s", head, map[0].name);
91-
for (int index = 1; map[index].name; ++index) {
92-
fprintf(file, "\n%s\t\t :%s", head, map[index].name);
91+
for (int i = 1; map[i].name; ++i) {
92+
fprintf(file, "\n%s\t\t :%s", head, map[i].name);
9393
}
9494
fprintf(file, ")\n");
9595
}

0 commit comments

Comments
 (0)