* [PATCH v2 0/3] Fix LLP64 `(size_t)1` compatibility VS C4334 warnings
@ 2021-12-01 0:28 Philip Oakley
2021-12-01 0:29 ` [PATCH v2 1/3] repack.c: LLP64 compatibility, upcast unity for left shift Philip Oakley
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Philip Oakley @ 2021-12-01 0:28 UTC (permalink / raw)
To: GitList, Junio C Hamano
Cc: René Scharfe, Johannes Schindelin, Derrick Stolee,
Taylor Blau, Philip Oakley
Since V1 (gitster/po/size-t-for-vs)
https://lore.kernel.org/git/20211126113614.709-1-philipoakley@iee.email/
Former patch 1/4 was dropped as it was already in Junio's tree.
Patch 1/3 corrects my spelling mistake.
Patch 2/3 has added extra spacing around the << operator as suggested by
Stollee[1].
Patch 3/3 removes the superceded commit message comment regarding
backporting the patch onto maint.
The Visual Studio MSVC compilation reports a number of C4334 "was 64-bit
shift intended" size mismatch warnings. In most of these cases a size_t
is ANDed (masked) with a bit shift of 1, or 1U. On LLP64 systems the unity
value is 32 bits, while size_t is 64 bits.
The fix is to upcast the unity value to size_t.
The first [dropped] patch had been reported [2] by René Scharfe as an extra patch
to the rs/mergesort series.
These fixes clear all the current C4334 warnings.
[1] https://lore.kernel.org/git/?q=%3Cf721bc99-6d79-e2f2-7810-dd77b777161f%40gmail.com%3E
[2] https://lore.kernel.org/git/7fbd4cf4-5f66-a4cd-0c41-e5b12d14d761@iee.email/
Philip Oakley (3):
repack.c: LLP64 compatibility, upcast unity for left shift
diffcore-delta.c: LLP64 compatibility, upcast unity for left shift
object-file.c: LLP64 compatibility, upcast unity for left shift
builtin/repack.c | 2 +-
diffcore-delta.c | 6 +++---
object-file.c | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
Range-diff against v1:
1: c00e082ed8 < -: ---------- mergesort.c: LLP64 compatibility, upcast unity for left shift
2: 85506c7e77 ! 1: 13d9b3fd6d repack.c: LLP64 compatibility, upcast unity for left shift
@@ Commit message
repack.c: LLP64 compatibility, upcast unity for left shift
Visual Studio reports C4334 "was 64-bit shift intended" warning
- because of size miss-match.
+ because of size mismatch.
Promote unity to the matching type to fit with the `&` operator.
3: 2072852f61 ! 2: b6c7ad9177 diffcore-delta.c: LLP64 compatibility, upcast unity for left shift
@@ diffcore-delta.c: static struct spanhash_top *hash_chars(struct repository *r,
i = INITIAL_HASH_SIZE;
hash = xmalloc(st_add(sizeof(*hash),
- st_mult(sizeof(struct spanhash), 1<<i)));
-+ st_mult(sizeof(struct spanhash), (size_t)1<<i)));
++ st_mult(sizeof(struct spanhash), (size_t)1 << i)));
hash->alloc_log2 = i;
hash->free = INITIAL_FREE(i);
- memset(hash->data, 0, sizeof(struct spanhash) * (1<<i));
4: 3b8f33fb28 ! 3: 0fa0d0a8c6 object-file.c: LLP64 compatibility, upcast unity for left shift
@@ Commit message
Signed-off-by: Philip Oakley <philipoakley@iee.email>
- ---
-
- This cannot be applied to the maint-2.32 branch as the earlier René Scharfe
- patch had been, because the original sha1-file.c, to which the backport
- would apply, has been renamed in e5afd4449d (object-file.c: rename
- from sha1-file.c, 2020-12-31) which was merged in 8b327f1784
- (Merge branch 'ma/sha1-is-a-hash', 2021-01-15)
-
## object-file.c ##
@@ object-file.c: struct oidtree *odb_loose_cache(struct object_directory *odb,
struct strbuf buf = STRBUF_INIT;
--
2.34.0.rc1.windows.1.4.ga126985b17
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/3] repack.c: LLP64 compatibility, upcast unity for left shift
2021-12-01 0:28 [PATCH v2 0/3] Fix LLP64 `(size_t)1` compatibility VS C4334 warnings Philip Oakley
@ 2021-12-01 0:29 ` Philip Oakley
2021-12-01 0:29 ` [PATCH v2 2/3] diffcore-delta.c: " Philip Oakley
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Philip Oakley @ 2021-12-01 0:29 UTC (permalink / raw)
To: GitList, Junio C Hamano
Cc: René Scharfe, Johannes Schindelin, Derrick Stolee,
Taylor Blau, Philip Oakley
Visual Studio reports C4334 "was 64-bit shift intended" warning
because of size mismatch.
Promote unity to the matching type to fit with the `&` operator.
Signed-off-by: Philip Oakley <philipoakley@iee.email>
---
builtin/repack.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/repack.c b/builtin/repack.c
index 0b2d1e5d82..6da66474fd 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -842,7 +842,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
fname_old = mkpathdup("%s-%s%s",
packtmp, item->string, exts[ext].name);
- if (((uintptr_t)item->util) & (1 << ext)) {
+ if (((uintptr_t)item->util) & ((uintptr_t)1 << ext)) {
struct stat statbuffer;
if (!stat(fname_old, &statbuffer)) {
statbuffer.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
--
2.34.0.rc1.windows.1.4.ga126985b17
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/3] diffcore-delta.c: LLP64 compatibility, upcast unity for left shift
2021-12-01 0:28 [PATCH v2 0/3] Fix LLP64 `(size_t)1` compatibility VS C4334 warnings Philip Oakley
2021-12-01 0:29 ` [PATCH v2 1/3] repack.c: LLP64 compatibility, upcast unity for left shift Philip Oakley
@ 2021-12-01 0:29 ` Philip Oakley
2021-12-01 0:29 ` [PATCH v2 3/3] object-file.c: " Philip Oakley
2021-12-01 22:49 ` [PATCH v2 0/3] Fix LLP64 `(size_t)1` compatibility VS C4334 warnings Junio C Hamano
3 siblings, 0 replies; 6+ messages in thread
From: Philip Oakley @ 2021-12-01 0:29 UTC (permalink / raw)
To: GitList, Junio C Hamano
Cc: René Scharfe, Johannes Schindelin, Derrick Stolee,
Taylor Blau, Philip Oakley
Visual Studio reports C4334 "was 64-bit shift intended" warning
because of size miss-match.
Promote unity to the matching type to fit with its subsequent operation.
Signed-off-by: Philip Oakley <philipoakley@iee.email>
---
diffcore-delta.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/diffcore-delta.c b/diffcore-delta.c
index 5668ace60d..18d8f766d7 100644
--- a/diffcore-delta.c
+++ b/diffcore-delta.c
@@ -133,10 +133,10 @@ static struct spanhash_top *hash_chars(struct repository *r,
i = INITIAL_HASH_SIZE;
hash = xmalloc(st_add(sizeof(*hash),
- st_mult(sizeof(struct spanhash), 1<<i)));
+ st_mult(sizeof(struct spanhash), (size_t)1 << i)));
hash->alloc_log2 = i;
hash->free = INITIAL_FREE(i);
- memset(hash->data, 0, sizeof(struct spanhash) * (1<<i));
+ memset(hash->data, 0, sizeof(struct spanhash) * ((size_t)1 << i));
n = 0;
accum1 = accum2 = 0;
@@ -159,7 +159,7 @@ static struct spanhash_top *hash_chars(struct repository *r,
n = 0;
accum1 = accum2 = 0;
}
- QSORT(hash->data, 1ul << hash->alloc_log2, spanhash_cmp);
+ QSORT(hash->data, (size_t)1ul << hash->alloc_log2, spanhash_cmp);
return hash;
}
--
2.34.0.rc1.windows.1.4.ga126985b17
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 3/3] object-file.c: LLP64 compatibility, upcast unity for left shift
2021-12-01 0:28 [PATCH v2 0/3] Fix LLP64 `(size_t)1` compatibility VS C4334 warnings Philip Oakley
2021-12-01 0:29 ` [PATCH v2 1/3] repack.c: LLP64 compatibility, upcast unity for left shift Philip Oakley
2021-12-01 0:29 ` [PATCH v2 2/3] diffcore-delta.c: " Philip Oakley
@ 2021-12-01 0:29 ` Philip Oakley
2021-12-01 22:49 ` [PATCH v2 0/3] Fix LLP64 `(size_t)1` compatibility VS C4334 warnings Junio C Hamano
3 siblings, 0 replies; 6+ messages in thread
From: Philip Oakley @ 2021-12-01 0:29 UTC (permalink / raw)
To: GitList, Junio C Hamano
Cc: René Scharfe, Johannes Schindelin, Derrick Stolee,
Taylor Blau, Philip Oakley
Visual Studio reports C4334 "was 64-bit shift intended" warning because
of size miss-match.
Promote unity to the matching type to fit with the assignment.
Signed-off-by: Philip Oakley <philipoakley@iee.email>
---
object-file.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/object-file.c b/object-file.c
index c3d866a287..da8821cb91 100644
--- a/object-file.c
+++ b/object-file.c
@@ -2425,7 +2425,7 @@ struct oidtree *odb_loose_cache(struct object_directory *odb,
struct strbuf buf = STRBUF_INIT;
size_t word_bits = bitsizeof(odb->loose_objects_subdir_seen[0]);
size_t word_index = subdir_nr / word_bits;
- size_t mask = 1u << (subdir_nr % word_bits);
+ size_t mask = (size_t)1u << (subdir_nr % word_bits);
uint32_t *bitmap;
if (subdir_nr < 0 ||
--
2.34.0.rc1.windows.1.4.ga126985b17
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/3] Fix LLP64 `(size_t)1` compatibility VS C4334 warnings
2021-12-01 0:28 [PATCH v2 0/3] Fix LLP64 `(size_t)1` compatibility VS C4334 warnings Philip Oakley
` (2 preceding siblings ...)
2021-12-01 0:29 ` [PATCH v2 3/3] object-file.c: " Philip Oakley
@ 2021-12-01 22:49 ` Junio C Hamano
2021-12-02 20:56 ` Derrick Stolee
3 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2021-12-01 22:49 UTC (permalink / raw)
To: Philip Oakley
Cc: GitList, René Scharfe, Johannes Schindelin, Derrick Stolee,
Taylor Blau
Philip Oakley <philipoakley@iee.email> writes:
> Since V1 (gitster/po/size-t-for-vs)
> https://lore.kernel.org/git/20211126113614.709-1-philipoakley@iee.email/
>
> Former patch 1/4 was dropped as it was already in Junio's tree.
>
> Patch 1/3 corrects my spelling mistake.
>
> Patch 2/3 has added extra spacing around the << operator as suggested by
> Stollee[1].
>
> Patch 3/3 removes the superceded commit message comment regarding
> backporting the patch onto maint.
>
> The Visual Studio MSVC compilation reports a number of C4334 "was 64-bit
> shift intended" size mismatch warnings. In most of these cases a size_t
> is ANDed (masked) with a bit shift of 1, or 1U. On LLP64 systems the unity
> value is 32 bits, while size_t is 64 bits.
>
> The fix is to upcast the unity value to size_t.
>
> The first [dropped] patch had been reported [2] by René Scharfe as an extra patch
> to the rs/mergesort series.
>
> These fixes clear all the current C4334 warnings.
Thanks. Will queue; let's have it in 'next'.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/3] Fix LLP64 `(size_t)1` compatibility VS C4334 warnings
2021-12-01 22:49 ` [PATCH v2 0/3] Fix LLP64 `(size_t)1` compatibility VS C4334 warnings Junio C Hamano
@ 2021-12-02 20:56 ` Derrick Stolee
0 siblings, 0 replies; 6+ messages in thread
From: Derrick Stolee @ 2021-12-02 20:56 UTC (permalink / raw)
To: Junio C Hamano, Philip Oakley
Cc: GitList, René Scharfe, Johannes Schindelin, Taylor Blau
On 12/1/2021 5:49 PM, Junio C Hamano wrote:
> Philip Oakley <philipoakley@iee.email> writes:
>
>> Since V1 (gitster/po/size-t-for-vs)
>> https://lore.kernel.org/git/20211126113614.709-1-philipoakley@iee.email/
>>
>> Former patch 1/4 was dropped as it was already in Junio's tree.
>>
>> Patch 1/3 corrects my spelling mistake.
>>
>> Patch 2/3 has added extra spacing around the << operator as suggested by
>> Stollee[1].
>>
>> Patch 3/3 removes the superceded commit message comment regarding
>> backporting the patch onto maint.
>>
>> The Visual Studio MSVC compilation reports a number of C4334 "was 64-bit
>> shift intended" size mismatch warnings. In most of these cases a size_t
>> is ANDed (masked) with a bit shift of 1, or 1U. On LLP64 systems the unity
>> value is 32 bits, while size_t is 64 bits.
>>
>> The fix is to upcast the unity value to size_t.
>>
>> The first [dropped] patch had been reported [2] by René Scharfe as an extra patch
>> to the rs/mergesort series.
>>
>> These fixes clear all the current C4334 warnings.
>
> Thanks. Will queue; let's have it in 'next'.
I agree. This version is excellent.
-Stolee
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-12-02 20:56 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-01 0:28 [PATCH v2 0/3] Fix LLP64 `(size_t)1` compatibility VS C4334 warnings Philip Oakley
2021-12-01 0:29 ` [PATCH v2 1/3] repack.c: LLP64 compatibility, upcast unity for left shift Philip Oakley
2021-12-01 0:29 ` [PATCH v2 2/3] diffcore-delta.c: " Philip Oakley
2021-12-01 0:29 ` [PATCH v2 3/3] object-file.c: " Philip Oakley
2021-12-01 22:49 ` [PATCH v2 0/3] Fix LLP64 `(size_t)1` compatibility VS C4334 warnings Junio C Hamano
2021-12-02 20:56 ` Derrick Stolee
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).