Skip to content

Commit 4473953

Browse files
authored
Merge pull request #415 from libtom/pr/clang-tidy-else-after-return
fix clang-tidy warning: readability-else-after-return
2 parents 6ac6d36 + ed2ec2e commit 4473953

33 files changed

+230
-189
lines changed

.ci/clang-tidy.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
# output version
4+
bash .ci/printinfo.sh
5+
6+
# tested with clang-tidy from llvm-6.0.0
7+
# not tested with Travis-CI
8+
9+
#### we use the main test sets:
10+
# readability
11+
# misc
12+
# clang-analyzer
13+
# google
14+
# performance
15+
# modernize
16+
# cert
17+
# bugprone
18+
# portability
19+
20+
#### the following checks are skipped
21+
# google-readability-function-size
22+
# readability-function-size
23+
# google-readability-casting
24+
# readability-braces-around-statements
25+
# misc-macro-parentheses
26+
# clang-analyzer-valist.Uninitialized
27+
28+
echo "Run clang-tidy version"
29+
30+
clang-tidy --version || exit 1
31+
32+
echo "Run clang-tidy..."
33+
34+
clang-tidy src/*/*.c src/*/*/*.c src/*/*/*/*.c src/*/*/*/*/*.c -warnings-as-errors='*' --quiet --checks=-*,\
35+
readability-*,-readability-function-size,-readability-braces-around-statements,\
36+
misc-*,-misc-macro-parentheses,\
37+
clang-analyzer-*,-clang-analyzer-valist.Uninitialized,\
38+
google-*,-google-readability-function-size,-google-readability-casting,\
39+
performance-*,\
40+
modernize-*,\
41+
cert-*,\
42+
bugprone-*,\
43+
portability-* -- -DUSE_LTM -DLTM_DESC -Isrc/headers -I../libtommath || { echo "clang-tidy FAILED!"; exit 1; }
44+
45+
echo "clang-tidy ok"
46+
47+
exit 0
48+
49+
# ref: $Format:%D$
50+
# git commit: $Format:%H$
51+
# commit time: $Format:%ai$

src/ciphers/aes/aes.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -723,18 +723,19 @@ int ECB_KS(int *keysize)
723723
{
724724
LTC_ARGCHK(keysize != NULL);
725725

726-
if (*keysize < 16)
726+
if (*keysize < 16) {
727727
return CRYPT_INVALID_KEYSIZE;
728+
}
728729
if (*keysize < 24) {
729730
*keysize = 16;
730731
return CRYPT_OK;
731-
} else if (*keysize < 32) {
732+
}
733+
if (*keysize < 32) {
732734
*keysize = 24;
733735
return CRYPT_OK;
734-
} else {
735-
*keysize = 32;
736-
return CRYPT_OK;
737736
}
737+
*keysize = 32;
738+
return CRYPT_OK;
738739
}
739740

740741
#endif

src/ciphers/blowfish.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,8 @@ int blowfish_keysize(int *keysize)
580580

581581
if (*keysize < 8) {
582582
return CRYPT_INVALID_KEYSIZE;
583-
} else if (*keysize > 56) {
583+
}
584+
if (*keysize > 56) {
584585
*keysize = 56;
585586
}
586587
return CRYPT_OK;

src/ciphers/cast5.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,8 @@ int cast5_keysize(int *keysize)
707707
LTC_ARGCHK(keysize != NULL);
708708
if (*keysize < 5) {
709709
return CRYPT_INVALID_KEYSIZE;
710-
} else if (*keysize > 16) {
710+
}
711+
if (*keysize > 16) {
711712
*keysize = 16;
712713
}
713714
return CRYPT_OK;

src/ciphers/kasumi.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,8 @@ int kasumi_keysize(int *keysize)
243243
if (*keysize >= 16) {
244244
*keysize = 16;
245245
return CRYPT_OK;
246-
} else {
247-
return CRYPT_INVALID_KEYSIZE;
248246
}
247+
return CRYPT_INVALID_KEYSIZE;
249248
}
250249

251250
int kasumi_test(void)

src/ciphers/khazad.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,9 +843,8 @@ int khazad_keysize(int *keysize)
843843
if (*keysize >= 16) {
844844
*keysize = 16;
845845
return CRYPT_OK;
846-
} else {
847-
return CRYPT_INVALID_KEYSIZE;
848846
}
847+
return CRYPT_INVALID_KEYSIZE;
849848
}
850849

851850
#endif

src/ciphers/noekeon.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,9 @@ int noekeon_keysize(int *keysize)
314314
LTC_ARGCHK(keysize != NULL);
315315
if (*keysize < 16) {
316316
return CRYPT_INVALID_KEYSIZE;
317-
} else {
318-
*keysize = 16;
319-
return CRYPT_OK;
320317
}
318+
*keysize = 16;
319+
return CRYPT_OK;
321320
}
322321

323322
#endif

src/ciphers/rc2.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,8 @@ int rc2_keysize(int *keysize)
401401
LTC_ARGCHK(keysize != NULL);
402402
if (*keysize < 1) {
403403
return CRYPT_INVALID_KEYSIZE;
404-
} else if (*keysize > 128) {
404+
}
405+
if (*keysize > 128) {
405406
*keysize = 128;
406407
}
407408
return CRYPT_OK;

src/ciphers/rc5.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,8 @@ int rc5_keysize(int *keysize)
308308
LTC_ARGCHK(keysize != NULL);
309309
if (*keysize < 8) {
310310
return CRYPT_INVALID_KEYSIZE;
311-
} else if (*keysize > 128) {
311+
}
312+
if (*keysize > 128) {
312313
*keysize = 128;
313314
}
314315
return CRYPT_OK;

src/ciphers/rc6.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ int rc6_keysize(int *keysize)
318318
LTC_ARGCHK(keysize != NULL);
319319
if (*keysize < 8) {
320320
return CRYPT_INVALID_KEYSIZE;
321-
} else if (*keysize > 128) {
321+
}
322+
if (*keysize > 128) {
322323
*keysize = 128;
323324
}
324325
return CRYPT_OK;

0 commit comments

Comments
 (0)