diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-09-15 11:25:43 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-09-25 18:39:43 +0300 |
commit | eef2d639f6f0a20b7768b3e521b0d0339957baeb (patch) | |
tree | f7793698ebe56eb2f86637339cf013da5dbc659a /src/microhttpd/test_md5.c | |
parent | b50bed1269be493f453c24de196bf89229abd2fd (diff) | |
download | libmicrohttpd-eef2d639f6f0a20b7768b3e521b0d0339957baeb.tar.gz libmicrohttpd-eef2d639f6f0a20b7768b3e521b0d0339957baeb.zip |
test_{md5,sha{256,512_256}}: re-use of the context structure
The context structure declaration was moved outside the loops, it should
help to re-use the same memory area which may trigger more potential
bugs.
Diffstat (limited to 'src/microhttpd/test_md5.c')
-rw-r--r-- | src/microhttpd/test_md5.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/microhttpd/test_md5.c b/src/microhttpd/test_md5.c index cf7ccbd1..13f9d46e 100644 --- a/src/microhttpd/test_md5.c +++ b/src/microhttpd/test_md5.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libmicrohttpd | 2 | This file is part of libmicrohttpd |
3 | Copyright (C) 2019 Karlson2k (Evgeny Grin) | 3 | Copyright (C) 2019-2022 Evgeny Grin (Karlson2k) |
4 | 4 | ||
5 | This test tool is free software; you can redistribute it and/or | 5 | This test tool is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU General Public License as | 6 | modify it under the terms of the GNU General Public License as |
@@ -312,10 +312,10 @@ test1_str (void) | |||
312 | { | 312 | { |
313 | unsigned int i; | 313 | unsigned int i; |
314 | int num_failed = 0; | 314 | int num_failed = 0; |
315 | struct Md5Ctx ctx; | ||
315 | 316 | ||
316 | for (i = 0; i < units1_num; i++) | 317 | for (i = 0; i < units1_num; i++) |
317 | { | 318 | { |
318 | struct Md5Ctx ctx; | ||
319 | uint8_t digest[MD5_DIGEST_SIZE]; | 319 | uint8_t digest[MD5_DIGEST_SIZE]; |
320 | 320 | ||
321 | MHD_MD5_init (&ctx); | 321 | MHD_MD5_init (&ctx); |
@@ -334,10 +334,10 @@ test1_bin (void) | |||
334 | { | 334 | { |
335 | unsigned int i; | 335 | unsigned int i; |
336 | int num_failed = 0; | 336 | int num_failed = 0; |
337 | struct Md5Ctx ctx; | ||
337 | 338 | ||
338 | for (i = 0; i < units2_num; i++) | 339 | for (i = 0; i < units2_num; i++) |
339 | { | 340 | { |
340 | struct Md5Ctx ctx; | ||
341 | uint8_t digest[MD5_DIGEST_SIZE]; | 341 | uint8_t digest[MD5_DIGEST_SIZE]; |
342 | 342 | ||
343 | MHD_MD5_init (&ctx); | 343 | MHD_MD5_init (&ctx); |
@@ -356,10 +356,10 @@ test2_str (void) | |||
356 | { | 356 | { |
357 | unsigned int i; | 357 | unsigned int i; |
358 | int num_failed = 0; | 358 | int num_failed = 0; |
359 | struct Md5Ctx ctx; | ||
359 | 360 | ||
360 | for (i = 0; i < units1_num; i++) | 361 | for (i = 0; i < units1_num; i++) |
361 | { | 362 | { |
362 | struct Md5Ctx ctx; | ||
363 | uint8_t digest[MD5_DIGEST_SIZE]; | 363 | uint8_t digest[MD5_DIGEST_SIZE]; |
364 | size_t part_s = data_units1[i].str_l.len / 4; | 364 | size_t part_s = data_units1[i].str_l.len / 4; |
365 | 365 | ||
@@ -383,10 +383,10 @@ test2_bin (void) | |||
383 | { | 383 | { |
384 | unsigned int i; | 384 | unsigned int i; |
385 | int num_failed = 0; | 385 | int num_failed = 0; |
386 | struct Md5Ctx ctx; | ||
386 | 387 | ||
387 | for (i = 0; i < units2_num; i++) | 388 | for (i = 0; i < units2_num; i++) |
388 | { | 389 | { |
389 | struct Md5Ctx ctx; | ||
390 | uint8_t digest[MD5_DIGEST_SIZE]; | 390 | uint8_t digest[MD5_DIGEST_SIZE]; |
391 | size_t part_s = data_units2[i].bin_l.len * 2 / 3; | 391 | size_t part_s = data_units2[i].bin_l.len * 2 / 3; |
392 | 392 | ||
@@ -414,6 +414,7 @@ test_unaligned (void) | |||
414 | unsigned int offset; | 414 | unsigned int offset; |
415 | uint8_t *buf; | 415 | uint8_t *buf; |
416 | uint8_t *digest_buf; | 416 | uint8_t *digest_buf; |
417 | struct Md5Ctx ctx; | ||
417 | 418 | ||
418 | const struct data_unit2 *const tdata = data_units2 + DATA_POS; | 419 | const struct data_unit2 *const tdata = data_units2 + DATA_POS; |
419 | 420 | ||
@@ -424,7 +425,6 @@ test_unaligned (void) | |||
424 | 425 | ||
425 | for (offset = MAX_OFFSET; offset >= 1; --offset) | 426 | for (offset = MAX_OFFSET; offset >= 1; --offset) |
426 | { | 427 | { |
427 | struct Md5Ctx ctx; | ||
428 | uint8_t *unaligned_digest; | 428 | uint8_t *unaligned_digest; |
429 | uint8_t *unaligned_buf; | 429 | uint8_t *unaligned_buf; |
430 | 430 | ||