Patchwork [2,of,2,remotefilelog-ext] remotefilelog: explicitly cast from data_offset_t to (s)size_t

login
register
mail settings
Submitter via Mercurial-devel
Date April 4, 2017, 5:32 p.m.
Message ID <44a00c1d4a66c23e1194.1491327154@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/19959/
State Accepted
Delegated to: Jun Wu
Headers show

Comments

via Mercurial-devel - April 4, 2017, 5:32 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1491327121 25200
#      Tue Apr 04 10:32:01 2017 -0700
# Node ID 44a00c1d4a66c23e11946e311145ee32bb7a0547
# Parent  c6a91402499e92d3829761521436ead8a42dc2ee
remotefilelog: explicitly cast from data_offset_t to (s)size_t

data_offset_t is always 64 bits and (s)size_t are sometimes 32 bits.
Jun Wu - April 4, 2017, 6:56 p.m.
Pushed. Thanks!

Excerpts from Martin von Zweigbergk's message of 2017-04-04 10:32:34 -0700:
> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz@google.com>
> # Date 1491327121 25200
> #      Tue Apr 04 10:32:01 2017 -0700
> # Node ID 44a00c1d4a66c23e11946e311145ee32bb7a0547
> # Parent  c6a91402499e92d3829761521436ead8a42dc2ee
> remotefilelog: explicitly cast from data_offset_t to (s)size_t
> 
> data_offset_t is always 64 bits and (s)size_t are sometimes 32 bits.
> 
> diff -r c6a91402499e -r 44a00c1d4a66 cstore/uniondatapackstore.cpp
> --- a/cstore/uniondatapackstore.cpp    Tue Apr 04 10:25:17 2017 -0700
> +++ b/cstore/uniondatapackstore.cpp    Tue Apr 04 10:32:01 2017 -0700
> @@ -36,7 +36,8 @@
>    delta_chain_link_t *link = links->at(index);
>  
>    struct mpatch_flist *res;
> -  if ((mpatch_decode((const char*)link->delta, link->delta_sz, &res)) < 0) {
> +  if ((mpatch_decode((const char*)link->delta,
> +             (ssize_t)link->delta_sz, &res)) < 0) {
>      throw std::logic_error("invalid patch during patch application");
>    }
>  
> @@ -59,8 +60,8 @@
>    // Short circuit and just return the full text if it's one long
>    if (links.size() == 0) {
>      char * finalText = new char[fulltextLink->delta_sz];
> -    memcpy(finalText, fulltextLink->delta, fulltextLink->delta_sz);
> -    return ConstantStringRef(finalText, fulltextLink->delta_sz);
> +    memcpy(finalText, fulltextLink->delta, (size_t)fulltextLink->delta_sz);
> +    return ConstantStringRef(finalText, (size_t)fulltextLink->delta_sz);
>    }
>  
>    std::reverse(links.begin(), links.end());
> @@ -70,14 +71,15 @@
>      throw std::logic_error("mpatch failed to fold patches");
>    }
>  
> -  ssize_t outlen = mpatch_calcsize(fulltextLink->delta_sz, patch);
> +  ssize_t outlen = mpatch_calcsize((ssize_t)fulltextLink->delta_sz, patch);
>    if (outlen < 0) {
>      mpatch_lfree(patch);
>      throw std::logic_error("mpatch failed to calculate size");
>    }
>  
>    char *result= new char[outlen];
> -  if (mpatch_apply(result, (const char*)fulltextLink->delta, fulltextLink->delta_sz, patch) < 0) {
> +  if (mpatch_apply(result, (const char*)fulltextLink->delta,
> +           (ssize_t)fulltextLink->delta_sz, patch) < 0) {
>      delete[] result;
>      mpatch_lfree(patch);
>      throw std::logic_error("mpatch failed to apply patches");

Patch

diff -r c6a91402499e -r 44a00c1d4a66 cstore/uniondatapackstore.cpp
--- a/cstore/uniondatapackstore.cpp	Tue Apr 04 10:25:17 2017 -0700
+++ b/cstore/uniondatapackstore.cpp	Tue Apr 04 10:32:01 2017 -0700
@@ -36,7 +36,8 @@ 
   delta_chain_link_t *link = links->at(index);
 
   struct mpatch_flist *res;
-  if ((mpatch_decode((const char*)link->delta, link->delta_sz, &res)) < 0) {
+  if ((mpatch_decode((const char*)link->delta,
+		     (ssize_t)link->delta_sz, &res)) < 0) {
     throw std::logic_error("invalid patch during patch application");
   }
 
@@ -59,8 +60,8 @@ 
   // Short circuit and just return the full text if it's one long
   if (links.size() == 0) {
     char * finalText = new char[fulltextLink->delta_sz];
-    memcpy(finalText, fulltextLink->delta, fulltextLink->delta_sz);
-    return ConstantStringRef(finalText, fulltextLink->delta_sz);
+    memcpy(finalText, fulltextLink->delta, (size_t)fulltextLink->delta_sz);
+    return ConstantStringRef(finalText, (size_t)fulltextLink->delta_sz);
   }
 
   std::reverse(links.begin(), links.end());
@@ -70,14 +71,15 @@ 
     throw std::logic_error("mpatch failed to fold patches");
   }
 
-  ssize_t outlen = mpatch_calcsize(fulltextLink->delta_sz, patch);
+  ssize_t outlen = mpatch_calcsize((ssize_t)fulltextLink->delta_sz, patch);
   if (outlen < 0) {
     mpatch_lfree(patch);
     throw std::logic_error("mpatch failed to calculate size");
   }
 
   char *result= new char[outlen];
-  if (mpatch_apply(result, (const char*)fulltextLink->delta, fulltextLink->delta_sz, patch) < 0) {
+  if (mpatch_apply(result, (const char*)fulltextLink->delta,
+		   (ssize_t)fulltextLink->delta_sz, patch) < 0) {
     delete[] result;
     mpatch_lfree(patch);
     throw std::logic_error("mpatch failed to apply patches");