{"thread":{"id":"57006","subject":"[PATCH v2 0/3] Fix LLP64 `(size_t)1` compatibility VS C4334 warnings","startedAt":"2021-12-01T00:29:13Z","lastAt":"2021-12-02T20:56:31Z","messageCount":6,"participants":["Philip Oakley","Junio C Hamano","Derrick Stolee"],"isPatch":true,"patchVersion":2,"patchTotal":3},"messages":[{"id":"442727","messageId":"20211201002902.1042-1-philipoakley@iee.email","threadId":"57006","inReplyTo":null,"subject":"[PATCH v2 0/3] Fix LLP64 `(size_t)1` compatibility VS C4334 warnings","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.email","sentAt":"2021-12-01T00:28:59Z","receivedAt":"2021-12-01T00:29:13Z","isPatch":true,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"Since V1 (gitster/po/size-t-for-vs)\nhttps://lore.kernel.org/git/20211126113614.709-1-philipoakley@iee.email/\n\nFormer patch 1/4 was dropped as it was already in Junio's tree.\n\nPatch 1/3 corrects my spelling mistake.\n\nPatch 2/3 has added extra spacing around the << operator as suggested by\nStollee[1].\n\nPatch 3/3 removes the superceded commit message comment regarding\nbackporting the patch onto maint.\n\nThe Visual Studio MSVC compilation reports a number of C4334 \"was 64-bit\nshift intended\" size mismatch warnings. In most of these cases a size_t\nis ANDed (masked) with a bit shift of 1, or 1U. On LLP64 systems the unity\nvalue is 32 bits, while size_t is 64 bits. \n\nThe fix is to upcast the unity value to size_t.   \n\nThe first [dropped] patch had been reported [2] by René Scharfe as an extra patch\nto the rs/mergesort series.\n\nThese fixes clear all the current C4334 warnings.\n\n[1] https://lore.kernel.org/git/?q=%3Cf721bc99-6d79-e2f2-7810-dd77b777161f%40gmail.com%3E\n[2] https://lore.kernel.org/git/7fbd4cf4-5f66-a4cd-0c41-e5b12d14d761@iee.email/\n\nPhilip Oakley (3):\n  repack.c: LLP64 compatibility, upcast unity for left shift\n  diffcore-delta.c: LLP64 compatibility, upcast unity for left shift\n  object-file.c: LLP64 compatibility, upcast unity for left shift\n\n builtin/repack.c | 2 +-\n diffcore-delta.c | 6 +++---\n object-file.c    | 2 +-\n 3 files changed, 5 insertions(+), 5 deletions(-)\n\nRange-diff against v1:\n1:  c00e082ed8 < -:  ---------- mergesort.c: LLP64 compatibility, upcast unity for left shift\n2:  85506c7e77 ! 1:  13d9b3fd6d repack.c: LLP64 compatibility, upcast unity for left shift\n    @@ Commit message\n         repack.c: LLP64 compatibility, upcast unity for left shift\n     \n         Visual Studio reports C4334 \"was 64-bit shift intended\" warning\n    -    because of size miss-match.\n    +    because of size mismatch.\n     \n         Promote unity to the matching type to fit with the `&` operator.\n     \n3:  2072852f61 ! 2:  b6c7ad9177 diffcore-delta.c: LLP64 compatibility, upcast unity for left shift\n    @@ diffcore-delta.c: static struct spanhash_top *hash_chars(struct repository *r,\n      \ti = INITIAL_HASH_SIZE;\n      \thash = xmalloc(st_add(sizeof(*hash),\n     -\t\t\t      st_mult(sizeof(struct spanhash), 1<<i)));\n    -+\t\t\t      st_mult(sizeof(struct spanhash), (size_t)1<<i)));\n    ++\t\t\t      st_mult(sizeof(struct spanhash), (size_t)1 << i)));\n      \thash->alloc_log2 = i;\n      \thash->free = INITIAL_FREE(i);\n     -\tmemset(hash->data, 0, sizeof(struct spanhash) * (1<<i));\n4:  3b8f33fb28 ! 3:  0fa0d0a8c6 object-file.c: LLP64 compatibility, upcast unity for left shift\n    @@ Commit message\n     \n         Signed-off-by: Philip Oakley <philipoakley@iee.email>\n     \n    -    ---\n    -\n    -    This cannot be applied to the maint-2.32 branch as the earlier René Scharfe\n    -    patch had been, because the original sha1-file.c, to which the backport\n    -    would apply, has been renamed in e5afd4449d (object-file.c: rename\n    -    from sha1-file.c, 2020-12-31) which was merged in 8b327f1784\n    -    (Merge branch 'ma/sha1-is-a-hash', 2021-01-15)\n    -\n      ## object-file.c ##\n     @@ object-file.c: struct oidtree *odb_loose_cache(struct object_directory *odb,\n      \tstruct strbuf buf = STRBUF_INIT;\n-- \n2.34.0.rc1.windows.1.4.ga126985b17\n\n"},{"id":"442728","messageId":"20211201002902.1042-2-philipoakley@iee.email","threadId":"57006","inReplyTo":"20211201002902.1042-1-philipoakley@iee.email","subject":"[PATCH v2 1/3] repack.c: LLP64 compatibility, upcast unity for left shift","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.email","sentAt":"2021-12-01T00:29:00Z","receivedAt":"2021-12-01T00:29:14Z","isPatch":true,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"Visual Studio reports C4334 \"was 64-bit shift intended\" warning\nbecause of size mismatch.\n\nPromote unity to the matching type to fit with the `&` operator.\n\nSigned-off-by: Philip Oakley <philipoakley@iee.email>\n---\n builtin/repack.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/repack.c b/builtin/repack.c\nindex 0b2d1e5d82..6da66474fd 100644\n--- a/builtin/repack.c\n+++ b/builtin/repack.c\n@@ -842,7 +842,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)\n \t\t\tfname_old = mkpathdup(\"%s-%s%s\",\n \t\t\t\t\tpacktmp, item->string, exts[ext].name);\n \n-\t\t\tif (((uintptr_t)item->util) & (1 << ext)) {\n+\t\t\tif (((uintptr_t)item->util) & ((uintptr_t)1 << ext)) {\n \t\t\t\tstruct stat statbuffer;\n \t\t\t\tif (!stat(fname_old, &statbuffer)) {\n \t\t\t\t\tstatbuffer.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);\n-- \n2.34.0.rc1.windows.1.4.ga126985b17\n\n"},{"id":"442729","messageId":"20211201002902.1042-3-philipoakley@iee.email","threadId":"57006","inReplyTo":"20211201002902.1042-1-philipoakley@iee.email","subject":"[PATCH v2 2/3] diffcore-delta.c: LLP64 compatibility, upcast unity for left shift","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.email","sentAt":"2021-12-01T00:29:01Z","receivedAt":"2021-12-01T00:29:15Z","isPatch":true,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"Visual Studio reports C4334 \"was 64-bit shift intended\" warning\nbecause of size miss-match.\n\nPromote unity to the matching type to fit with its subsequent operation.\n\nSigned-off-by: Philip Oakley <philipoakley@iee.email>\n---\n diffcore-delta.c | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/diffcore-delta.c b/diffcore-delta.c\nindex 5668ace60d..18d8f766d7 100644\n--- a/diffcore-delta.c\n+++ b/diffcore-delta.c\n@@ -133,10 +133,10 @@ static struct spanhash_top *hash_chars(struct repository *r,\n \n \ti = INITIAL_HASH_SIZE;\n \thash = xmalloc(st_add(sizeof(*hash),\n-\t\t\t      st_mult(sizeof(struct spanhash), 1<<i)));\n+\t\t\t      st_mult(sizeof(struct spanhash), (size_t)1 << i)));\n \thash->alloc_log2 = i;\n \thash->free = INITIAL_FREE(i);\n-\tmemset(hash->data, 0, sizeof(struct spanhash) * (1<<i));\n+\tmemset(hash->data, 0, sizeof(struct spanhash) * ((size_t)1 << i));\n \n \tn = 0;\n \taccum1 = accum2 = 0;\n@@ -159,7 +159,7 @@ static struct spanhash_top *hash_chars(struct repository *r,\n \t\tn = 0;\n \t\taccum1 = accum2 = 0;\n \t}\n-\tQSORT(hash->data, 1ul << hash->alloc_log2, spanhash_cmp);\n+\tQSORT(hash->data, (size_t)1ul << hash->alloc_log2, spanhash_cmp);\n \treturn hash;\n }\n \n-- \n2.34.0.rc1.windows.1.4.ga126985b17\n\n"},{"id":"442730","messageId":"20211201002902.1042-4-philipoakley@iee.email","threadId":"57006","inReplyTo":"20211201002902.1042-1-philipoakley@iee.email","subject":"[PATCH v2 3/3] object-file.c: LLP64 compatibility, upcast unity for left shift","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.email","sentAt":"2021-12-01T00:29:02Z","receivedAt":"2021-12-01T00:29:17Z","isPatch":true,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"Visual Studio reports C4334 \"was 64-bit shift intended\" warning because\nof size miss-match.\n\nPromote unity to the matching type to fit with the assignment.\n\nSigned-off-by: Philip Oakley <philipoakley@iee.email>\n---\n object-file.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/object-file.c b/object-file.c\nindex c3d866a287..da8821cb91 100644\n--- a/object-file.c\n+++ b/object-file.c\n@@ -2425,7 +2425,7 @@ struct oidtree *odb_loose_cache(struct object_directory *odb,\n \tstruct strbuf buf = STRBUF_INIT;\n \tsize_t word_bits = bitsizeof(odb->loose_objects_subdir_seen[0]);\n \tsize_t word_index = subdir_nr / word_bits;\n-\tsize_t mask = 1u << (subdir_nr % word_bits);\n+\tsize_t mask = (size_t)1u << (subdir_nr % word_bits);\n \tuint32_t *bitmap;\n \n \tif (subdir_nr < 0 ||\n-- \n2.34.0.rc1.windows.1.4.ga126985b17\n\n"},{"id":"442824","messageId":"xmqq5ys8ym8s.fsf@gitster.g","threadId":"57006","inReplyTo":"20211201002902.1042-1-philipoakley@iee.email","subject":"Re: [PATCH v2 0/3] Fix LLP64 `(size_t)1` compatibility VS C4334 warnings","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-12-01T22:49:07Z","receivedAt":"2021-12-01T22:49:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Philip Oakley <philipoakley@iee.email> writes:\n\n> Since V1 (gitster/po/size-t-for-vs)\n> https://lore.kernel.org/git/20211126113614.709-1-philipoakley@iee.email/\n>\n> Former patch 1/4 was dropped as it was already in Junio's tree.\n>\n> Patch 1/3 corrects my spelling mistake.\n>\n> Patch 2/3 has added extra spacing around the << operator as suggested by\n> Stollee[1].\n>\n> Patch 3/3 removes the superceded commit message comment regarding\n> backporting the patch onto maint.\n>\n> The Visual Studio MSVC compilation reports a number of C4334 \"was 64-bit\n> shift intended\" size mismatch warnings. In most of these cases a size_t\n> is ANDed (masked) with a bit shift of 1, or 1U. On LLP64 systems the unity\n> value is 32 bits, while size_t is 64 bits. \n>\n> The fix is to upcast the unity value to size_t.   \n>\n> The first [dropped] patch had been reported [2] by René Scharfe as an extra patch\n> to the rs/mergesort series.\n>\n> These fixes clear all the current C4334 warnings.\n\nThanks.  Will queue; let's have it in 'next'.\n"},{"id":"442914","messageId":"cbcdcad7-16c5-b14d-5edc-5c91909b13e2@gmail.com","threadId":"57006","inReplyTo":"xmqq5ys8ym8s.fsf@gitster.g","subject":"Re: [PATCH v2 0/3] Fix LLP64 `(size_t)1` compatibility VS C4334 warnings","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2021-12-02T20:56:27Z","receivedAt":"2021-12-02T20:56:31Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 12/1/2021 5:49 PM, Junio C Hamano wrote:\n> Philip Oakley <philipoakley@iee.email> writes:\n> \n>> Since V1 (gitster/po/size-t-for-vs)\n>> https://lore.kernel.org/git/20211126113614.709-1-philipoakley@iee.email/\n>>\n>> Former patch 1/4 was dropped as it was already in Junio's tree.\n>>\n>> Patch 1/3 corrects my spelling mistake.\n>>\n>> Patch 2/3 has added extra spacing around the << operator as suggested by\n>> Stollee[1].\n>>\n>> Patch 3/3 removes the superceded commit message comment regarding\n>> backporting the patch onto maint.\n>>\n>> The Visual Studio MSVC compilation reports a number of C4334 \"was 64-bit\n>> shift intended\" size mismatch warnings. In most of these cases a size_t\n>> is ANDed (masked) with a bit shift of 1, or 1U. On LLP64 systems the unity\n>> value is 32 bits, while size_t is 64 bits. \n>>\n>> The fix is to upcast the unity value to size_t.   \n>>\n>> The first [dropped] patch had been reported [2] by René Scharfe as an extra patch\n>> to the rs/mergesort series.\n>>\n>> These fixes clear all the current C4334 warnings.\n> \n> Thanks.  Will queue; let's have it in 'next'.\n\nI agree. This version is excellent.\n\n-Stolee\n \n"}]}