git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 0/3] Fix LLP64 `(size_t)1` compatibility VS C4334 warnings

From
Philip Oakley <philipoakley@iee.email>
Date
Dec 1, 2021, 00:28 UTC
Message-ID
<20211201002902.1042-1-philipoakley@iee.email>

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
Next: Philip Oakley
Message 1 of 6 in “Fix LLP64 `(size_t)1` compatibility VS C4334 warnings”
  1. 0/3 Fix LLP64 `(size_t)1` compatibility VS C4334 warningsPhilip Oakley, Dec 1, 2021
  2. 1/3 repack.c: LLP64 compatibility, upcast unity for left shiftPhilip Oakley, Dec 1, 2021
  3. 2/3 diffcore-delta.c: LLP64 compatibility, upcast unity for left shiftPhilip Oakley, Dec 1, 2021
  4. 3/3 object-file.c: LLP64 compatibility, upcast unity for left shiftPhilip Oakley, Dec 1, 2021
  5. Junio C HamanoDec 1, 2021
  6. Derrick StoleeDec 2, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.