* [PATCH 3/4] msvc: Fix some compiler warnings
@ 2010-06-23 19:47 Ramsay Jones
2010-06-24 16:40 ` Junio C Hamano
0 siblings, 1 reply; 2+ messages in thread
From: Ramsay Jones @ 2010-06-23 19:47 UTC (permalink / raw)
To: Junio C Hamano; +Cc: GIT Mailing-list
In particular, using the normal (or production) compiler
warning level (-W3), msvc complains as follows:
.../sha1.c(244) : warning C4018: '<' : signed/unsigned mismatch
.../sha1.c(270) : warning C4244: 'function' : conversion from \
'unsigned __int64' to 'unsigned long', possible loss of data
.../sha1.c(271) : warning C4244: 'function' : conversion from \
'unsigned __int64' to 'unsigned long', possible loss of data
Note that gcc issues a similar complaint about line 244 when
compiling with -Wextra.
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
---
block-sha1/sha1.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/block-sha1/sha1.c b/block-sha1/sha1.c
index e102856..c0054a0 100644
--- a/block-sha1/sha1.c
+++ b/block-sha1/sha1.c
@@ -237,13 +237,13 @@ void blk_SHA1_Init(blk_SHA_CTX *ctx)
void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, unsigned long len)
{
- int lenW = ctx->size & 63;
+ unsigned int lenW = ctx->size & 63;
ctx->size += len;
/* Read the data into W and process blocks as they get full */
if (lenW) {
- int left = 64 - lenW;
+ unsigned int left = 64 - lenW;
if (len < left)
left = len;
memcpy(lenW + (char *)ctx->W, data, left);
@@ -270,8 +270,8 @@ void blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx)
int i;
/* Pad with a binary 1 (ie 0x80), then zeroes, then length */
- padlen[0] = htonl(ctx->size >> 29);
- padlen[1] = htonl(ctx->size << 3);
+ padlen[0] = htonl((uint32_t)(ctx->size >> 29));
+ padlen[1] = htonl((uint32_t)(ctx->size << 3));
i = ctx->size & 63;
blk_SHA1_Update(ctx, pad, 1+ (63 & (55 - i)));
--
1.7.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 3/4] msvc: Fix some compiler warnings
2010-06-23 19:47 [PATCH 3/4] msvc: Fix some compiler warnings Ramsay Jones
@ 2010-06-24 16:40 ` Junio C Hamano
0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2010-06-24 16:40 UTC (permalink / raw)
To: Ramsay Jones; +Cc: Linus Torvalds, GIT Mailing-list
Ramsay Jones <ramsay@ramsay1.demon.co.uk> writes:
> In particular, using the normal (or production) compiler
> warning level (-W3), msvc complains as follows:
>
> .../sha1.c(244) : warning C4018: '<' : signed/unsigned mismatch
> .../sha1.c(270) : warning C4244: 'function' : conversion from \
> 'unsigned __int64' to 'unsigned long', possible loss of data
> .../sha1.c(271) : warning C4244: 'function' : conversion from \
> 'unsigned __int64' to 'unsigned long', possible loss of data
>
> Note that gcc issues a similar complaint about line 244 when
> compiling with -Wextra.
>
> Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
I do not think it matters much, but ...
> block-sha1/sha1.c | 8 ++++----
> 1 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/block-sha1/sha1.c b/block-sha1/sha1.c
> index e102856..c0054a0 100644
> --- a/block-sha1/sha1.c
> +++ b/block-sha1/sha1.c
> @@ -237,13 +237,13 @@ void blk_SHA1_Init(blk_SHA_CTX *ctx)
>
> void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, unsigned long len)
> {
> - int lenW = ctx->size & 63;
> + unsigned int lenW = ctx->size & 63;
>
> ctx->size += len;
>
> /* Read the data into W and process blocks as they get full */
> if (lenW) {
> - int left = 64 - lenW;
> + unsigned int left = 64 - lenW;
> if (len < left)
> left = len;
> memcpy(lenW + (char *)ctx->W, data, left);
... surprisingly this patch changes the compiler output slightly.
Disassembly of section .text:
0000000000000000 <blk_SHA1_Init>:
...
unsigned int left = 64 - lenW;
11ee: bb 40 00 00 00 mov $0x40,%ebx
11f3: 44 29 f3 sub %r14d,%ebx
if (len < left)
- 11f6: 41 89 df mov %ebx,%r15d
+ 11f6: 4c 63 fb movslq %ebx,%r15
11f9: 4c 39 fd cmp %r15,%rbp
11fc: 73 05 jae 1203 <blk_SHA1_Update+0x53>
left = len;
11fe: 89 eb mov %ebp,%ebx
- 1200: 41 89 ef mov %ebp,%r15d
+ 1200: 4c 63 fd movslq %ebp,%r15
memcpy(lenW + (char *)ctx->W, data, left);
1203: 49 8d 45 1c lea 0x1c(%r13),%rax
- 1207: 44 89 f7 mov %r14d,%edi
+ 1207: 49 63 fe movslq %r14d,%rdi
120a: 4c 89 fa mov %r15,%rdx
120d: 4c 89 e6 mov %r12,%rsi
1210: 48 01 c7 add %rax,%rdi
1213: 48 89 04 24 mov %rax,(%rsp)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-06-24 16:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-23 19:47 [PATCH 3/4] msvc: Fix some compiler warnings Ramsay Jones
2010-06-24 16:40 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).