[PATCH] cipher/rijndael.c: Cast loop variable to unsigned in comparison

Paul Menzel paulepanter at users.sourceforge.net
Sat Apr 11 10:29:48 CEST 2015


Date: Sat, 11 Apr 2015 08:38:47 +0200

Currently, building GRUB, Clang 3.7 warns about a comparison of integers
of different size.

	clang-3.7 -DHAVE_CONFIG_H -I. -I..  -Wall -W  -DGRUB_MACHINE_COREBOOT=1 -DGRUB_MACHINE=I386_COREBOOT -m32 -msoft-float -Xclang -msoft-float -Xclang -no-implicit-float -nostdinc -isystem /usr/lib/llvm-3.7/bin/../lib/clang/3.7.0/include -I../include -I../include -DGRUB_FILE=\"lib/libgcrypt-grub/cipher/rijndael.c\" -I. -I. -I.. -I.. -I../include -I../include -I../grub-core/lib/libgcrypt-grub/src/   -I../grub-core/lib/libgcrypt_wrap -I../grub-core/lib/posix_wrap -D_GCRYPT_IN_LIBGCRYPT=1 -I../include/grub/gcrypt  -D_FILE_OFFSET_BITS=64 -Os -Wall -W -Wshadow -Wpointer-arith -Wundef -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wmain -Wmissing-braces -Wmissing-format-attribute -Wmultichar -Wparentheses -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value  -Wunused-variable -Wwrite-strings -Wnested-externs -Wstrict-prototypes -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations  -Wextra -Wattributes -Wendif-labels -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmissing-field-initializers -Wnonnull -Woverflow -Wvla -Wpointer-to-int-cast -Wstrict-aliasing -Wvariadic-macros -Wvolatile-register-var -Wpointer-sign -Wmissing-include-dirs -Wmissing-prototypes -Wmissing-declarations -Wformat=2 -march=i386 -m32 -malign-jumps=1 -malign-loops=1 -malign-functions=1 -freg-struct-return -mno-mmx -mno-sse -mno-sse2 -mno-3dnow -fno-dwarf2-cfi-asm -fno-asynchronous-unwind-tables -fno-stack-protector -Werror  -ffreestanding -Wno-error -Wno-missing-field-initializers -Wno-redundant-decls -Wno-undef -fno-builtin -Wno-cast-align   -MT lib/libgcrypt-grub/cipher/gcry_rijndael_module-rijndael.o -MD -MP -MF lib/libgcrypt-grub/cipher/.deps-core/gcry_rijndael_module-rijndael.Tpo -c -o lib/libgcrypt-grub/cipher/gcry_rijndael_module-rijndael.o `test -f 'lib/libgcrypt-grub/cipher/rijndael.c' || echo './'`lib/libgcrypt-grub/cipher/rijndael.c
	lib/libgcrypt-grub/cipher/rijndael.c:352:21: warning: comparison of integers of different signs: 'int' and 'const unsigned int'
	      [-Wsign-compare]
	      for (i = 0; i < keylen; i++)
                  ~ ^ ~~~~~~
	1 warning generated.

Address the warning by casting the loop variable `i` to unsigned in the
comparison.

Signed-off-by: Paul Menzel <paulepanter at users.sourceforge.net>
---
For some reason this warning is not shown when building Libgrypt 1.6.3
directly. But I did not investigate further.

 cipher/rijndael.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cipher/rijndael.c b/cipher/rijndael.c
index 8019f0a..b36f687 100644
--- a/cipher/rijndael.c
+++ b/cipher/rijndael.c
@@ -578,7 +578,7 @@ do_setkey (RIJNDAEL_context *ctx, const byte *key, const unsigned keylen)
 #define k k.data
 #define tk tk.data
 #define W (ctx->keyschenc)
-      for (i = 0; i < keylen; i++)
+      for (i = 0; (unsigned) i < keylen; i++)
         {
           k[i >> 2][i & 3] = key[i];
         }
-- 
2.1.4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part
URL: </pipermail/attachments/20150411/9a14e5c4/attachment-0001.sig>


More information about the Gcrypt-devel mailing list