{"thread":{"id":"24177","subject":"[PATCH 3/4] msvc: Fix some compiler warnings","startedAt":"2010-06-23T19:47:50Z","lastAt":"2010-06-24T16:40:41Z","messageCount":2,"participants":["Ramsay Jones","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"144099","messageId":"4C2264E6.4030209@ramsay1.demon.co.uk","threadId":"24177","inReplyTo":null,"subject":"[PATCH 3/4] msvc: Fix some compiler warnings","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsay1.demon.co.uk","sentAt":"2010-06-23T19:47:50Z","receivedAt":"2010-06-23T19:47:50Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\nIn particular, using the normal (or production) compiler\nwarning level (-W3), msvc complains as follows:\n\n.../sha1.c(244) : warning C4018: '<' : signed/unsigned mismatch\n.../sha1.c(270) : warning C4244: 'function' : conversion from \\\n   'unsigned __int64' to 'unsigned long', possible loss of data\n.../sha1.c(271) : warning C4244: 'function' : conversion from \\\n   'unsigned __int64' to 'unsigned long', possible loss of data\n\nNote that gcc issues a similar complaint about line 244 when\ncompiling with -Wextra.\n\nSigned-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>\n---\n block-sha1/sha1.c |    8 ++++----\n 1 files changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/block-sha1/sha1.c b/block-sha1/sha1.c\nindex e102856..c0054a0 100644\n--- a/block-sha1/sha1.c\n+++ b/block-sha1/sha1.c\n@@ -237,13 +237,13 @@ void blk_SHA1_Init(blk_SHA_CTX *ctx)\n \n void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, unsigned long len)\n {\n-\tint lenW = ctx->size & 63;\n+\tunsigned int lenW = ctx->size & 63;\n \n \tctx->size += len;\n \n \t/* Read the data into W and process blocks as they get full */\n \tif (lenW) {\n-\t\tint left = 64 - lenW;\n+\t\tunsigned int left = 64 - lenW;\n \t\tif (len < left)\n \t\t\tleft = len;\n \t\tmemcpy(lenW + (char *)ctx->W, data, left);\n@@ -270,8 +270,8 @@ void blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx)\n \tint i;\n \n \t/* Pad with a binary 1 (ie 0x80), then zeroes, then length */\n-\tpadlen[0] = htonl(ctx->size >> 29);\n-\tpadlen[1] = htonl(ctx->size << 3);\n+\tpadlen[0] = htonl((uint32_t)(ctx->size >> 29));\n+\tpadlen[1] = htonl((uint32_t)(ctx->size << 3));\n \n \ti = ctx->size & 63;\n \tblk_SHA1_Update(ctx, pad, 1+ (63 & (55 - i)));\n-- \n1.7.1\n"},{"id":"144161","messageId":"7v1vbwe646.fsf@alter.siamese.dyndns.org","threadId":"24177","inReplyTo":"4C2264E6.4030209@ramsay1.demon.co.uk","subject":"Re: [PATCH 3/4] msvc: Fix some compiler warnings","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-06-24T16:40:41Z","receivedAt":"2010-06-24T16:40:41Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramsay Jones <ramsay@ramsay1.demon.co.uk> writes:\n\n> In particular, using the normal (or production) compiler\n> warning level (-W3), msvc complains as follows:\n>\n> .../sha1.c(244) : warning C4018: '<' : signed/unsigned mismatch\n> .../sha1.c(270) : warning C4244: 'function' : conversion from \\\n>    'unsigned __int64' to 'unsigned long', possible loss of data\n> .../sha1.c(271) : warning C4244: 'function' : conversion from \\\n>    'unsigned __int64' to 'unsigned long', possible loss of data\n>\n> Note that gcc issues a similar complaint about line 244 when\n> compiling with -Wextra.\n>\n> Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>\n\nI do not think it matters much, but ...\n\n>  block-sha1/sha1.c |    8 ++++----\n>  1 files changed, 4 insertions(+), 4 deletions(-)\n>\n> diff --git a/block-sha1/sha1.c b/block-sha1/sha1.c\n> index e102856..c0054a0 100644\n> --- a/block-sha1/sha1.c\n> +++ b/block-sha1/sha1.c\n> @@ -237,13 +237,13 @@ void blk_SHA1_Init(blk_SHA_CTX *ctx)\n>  \n>  void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, unsigned long len)\n>  {\n> -\tint lenW = ctx->size & 63;\n> +\tunsigned int lenW = ctx->size & 63;\n>  \n>  \tctx->size += len;\n>  \n>  \t/* Read the data into W and process blocks as they get full */\n>  \tif (lenW) {\n> -\t\tint left = 64 - lenW;\n> +\t\tunsigned int left = 64 - lenW;\n>  \t\tif (len < left)\n>  \t\t\tleft = len;\n>  \t\tmemcpy(lenW + (char *)ctx->W, data, left);\n\n... surprisingly this patch changes the compiler output slightly.\n\n Disassembly of section .text:\n \n 0000000000000000 <blk_SHA1_Init>:\n ...\n \t\tunsigned int left = 64 - lenW;\n     11ee:\tbb 40 00 00 00       \tmov    $0x40,%ebx\n     11f3:\t44 29 f3             \tsub    %r14d,%ebx\n \t\tif (len < left)\n-    11f6:\t41 89 df             \tmov    %ebx,%r15d\n+    11f6:\t4c 63 fb             \tmovslq %ebx,%r15\n     11f9:\t4c 39 fd             \tcmp    %r15,%rbp\n     11fc:\t73 05                \tjae    1203 <blk_SHA1_Update+0x53>\n \t\t\tleft = len;\n     11fe:\t89 eb                \tmov    %ebp,%ebx\n-    1200:\t41 89 ef             \tmov    %ebp,%r15d\n+    1200:\t4c 63 fd             \tmovslq %ebp,%r15\n \t\tmemcpy(lenW + (char *)ctx->W, data, left);\n     1203:\t49 8d 45 1c          \tlea    0x1c(%r13),%rax\n-    1207:\t44 89 f7             \tmov    %r14d,%edi\n+    1207:\t49 63 fe             \tmovslq %r14d,%rdi\n     120a:\t4c 89 fa             \tmov    %r15,%rdx\n     120d:\t4c 89 e6             \tmov    %r12,%rsi\n     1210:\t48 01 c7             \tadd    %rax,%rdi\n     1213:\t48 89 04 24          \tmov    %rax,(%rsp)\n"}]}