{"thread":{"id":"36006","subject":"[PATCH] Replace memcpy with hashcpy when dealing hash copy globally","startedAt":"2014-03-01T01:07:04Z","lastAt":"2014-03-01T14:55:05Z","messageCount":6,"participants":["Sun He","Duy Nguyen","Tay Ray Chuan","He Sun"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"235685","messageId":"1393636024-17576-1-git-send-email-sunheehnus@gmail.com","threadId":"36006","inReplyTo":null,"subject":"[PATCH] Replace memcpy with hashcpy when dealing hash copy globally","fromName":"Sun He","fromEmail":"sunheehnus@gmail.com","sentAt":"2014-03-01T01:07:04Z","receivedAt":"2014-03-01T01:07:04Z","isPatch":true,"sender":{"key":"sunheehnus@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2889804?v=4"},"body":"Signed-off-by: Sun He <sunheehnus@gmail.com>\n---\n Find the potential places with memcpy by the bash command:\n   $ find . | xargs grep \"memcpy.*\\(.*20.*\\)\"\n\n Helped-by: Michael Haggerty<mhagger@alum.mit.edu>\n\n bundle.c            | 2 +-\n grep.c              | 2 +-\n pack-bitmap-write.c | 2 +-\n ppc/sha1.c          | 3 ++-\n reflog-walk.c       | 4 ++--\n refs.c              | 2 +-\n 6 files changed, 8 insertions(+), 7 deletions(-)\n\ndiff --git a/bundle.c b/bundle.c\nindex e99065c..7809fbb 100644\n--- a/bundle.c\n+++ b/bundle.c\n@@ -19,7 +19,7 @@ static void add_to_ref_list(const unsigned char *sha1, const char *name,\n \t\tlist->list = xrealloc(list->list,\n \t\t\t\tlist->alloc * sizeof(list->list[0]));\n \t}\n-\tmemcpy(list->list[list->nr].sha1, sha1, 20);\n+\thashcpy(list->list[list->nr].sha1, sha1);\n \tlist->list[list->nr].name = xstrdup(name);\n \tlist->nr++;\n }\ndiff --git a/grep.c b/grep.c\nindex c668034..f5101f7 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -1650,7 +1650,7 @@ void grep_source_init(struct grep_source *gs, enum grep_source_type type,\n \t\tbreak;\n \tcase GREP_SOURCE_SHA1:\n \t\tgs->identifier = xmalloc(20);\n-\t\tmemcpy(gs->identifier, identifier, 20);\n+\t\thashcpy(gs->identifier, identifier);\n \t\tbreak;\n \tcase GREP_SOURCE_BUF:\n \t\tgs->identifier = NULL;\ndiff --git a/pack-bitmap-write.c b/pack-bitmap-write.c\nindex 1218bef..5f1791a 100644\n--- a/pack-bitmap-write.c\n+++ b/pack-bitmap-write.c\n@@ -530,7 +530,7 @@ void bitmap_writer_finish(struct pack_idx_entry **index,\n \theader.version = htons(default_version);\n \theader.options = htons(flags | options);\n \theader.entry_count = htonl(writer.selected_nr);\n-\tmemcpy(header.checksum, writer.pack_checksum, 20);\n+\thashcpy(header.checksum, writer.pack_checksum);\n \n \tsha1write(f, &header, sizeof(header));\n \tdump_bitmap(f, writer.commits);\ndiff --git a/ppc/sha1.c b/ppc/sha1.c\nindex ec6a192..8a87fea 100644\n--- a/ppc/sha1.c\n+++ b/ppc/sha1.c\n@@ -9,6 +9,7 @@\n #include <stdio.h>\n #include <string.h>\n #include \"sha1.h\"\n+#include \"cache.h\"\n \n extern void ppc_sha1_core(uint32_t *hash, const unsigned char *p,\n \t\t\t  unsigned int nblocks);\n@@ -67,6 +68,6 @@ int ppc_SHA1_Final(unsigned char *hash, ppc_SHA_CTX *c)\n \t\tmemset(&c->buf.b[cnt], 0, 56 - cnt);\n \tc->buf.l[7] = c->len;\n \tppc_sha1_core(c->hash, c->buf.b, 1);\n-\tmemcpy(hash, c->hash, 20);\n+\thashcpy(hash, c->hash);\n \treturn 0;\n }\ndiff --git a/reflog-walk.c b/reflog-walk.c\nindex b2fbdb2..d490f7d 100644\n--- a/reflog-walk.c\n+++ b/reflog-walk.c\n@@ -32,8 +32,8 @@ static int read_one_reflog(unsigned char *osha1, unsigned char *nsha1,\n \t\t\tsizeof(struct reflog_info));\n \t}\n \titem = array->items + array->nr;\n-\tmemcpy(item->osha1, osha1, 20);\n-\tmemcpy(item->nsha1, nsha1, 20);\n+\thashcpy(item->osha1, osha1);\n+\thashcpy(item->nsha1, nsha1);\n \titem->email = xstrdup(email);\n \titem->timestamp = timestamp;\n \titem->tz = tz;\ndiff --git a/refs.c b/refs.c\nindex 89228e2..f90b7ea 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -1222,7 +1222,7 @@ static int resolve_gitlink_packed_ref(struct ref_cache *refs,\n \tif (ref == NULL)\n \t\treturn -1;\n \n-\tmemcpy(sha1, ref->u.value.sha1, 20);\n+\thashcpy(sha1, ref->u.value.sha1);\n \treturn 0;\n }\n \n-- \n1.9.0.138.g2de3478.dirty\n"},{"id":"235690","messageId":"CACsJy8Apoz43HPAgdrTHSNgSOcUhv9j258+r0xDJeioY3iogig@mail.gmail.com","threadId":"36006","inReplyTo":"1393636024-17576-1-git-send-email-sunheehnus@gmail.com","subject":"Re: [PATCH] Replace memcpy with hashcpy when dealing hash copy globally","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2014-03-01T02:58:50Z","receivedAt":"2014-03-01T02:58:50Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sat, Mar 1, 2014 at 8:07 AM, Sun He <sunheehnus@gmail.com> wrote:\n> Signed-off-by: Sun He <sunheehnus@gmail.com>\n> ---\n>  Find the potential places with memcpy by the bash command:\n>    $ find . | xargs grep \"memcpy.*\\(.*20.*\\)\"\n>\n>  Helped-by: Michael Haggerty<mhagger@alum.mit.edu>\n\nYou may want to put this Helped-by before \"---\" because it's supposed\nto end up in the final commit. The patch looks straightforward,\nexcept..\n\n> diff --git a/ppc/sha1.c b/ppc/sha1.c\n> index ec6a192..8a87fea 100644\n> --- a/ppc/sha1.c\n> +++ b/ppc/sha1.c\n> @@ -9,6 +9,7 @@\n>  #include <stdio.h>\n>  #include <string.h>\n>  #include \"sha1.h\"\n> +#include \"cache.h\"\n>\n>  extern void ppc_sha1_core(uint32_t *hash, const unsigned char *p,\n>                           unsigned int nblocks);\n> @@ -67,6 +68,6 @@ int ppc_SHA1_Final(unsigned char *hash, ppc_SHA_CTX *c)\n>                 memset(&c->buf.b[cnt], 0, 56 - cnt);\n>         c->buf.l[7] = c->len;\n>         ppc_sha1_core(c->hash, c->buf.b, 1);\n> -       memcpy(hash, c->hash, 20);\n> +       hashcpy(hash, c->hash);\n>         return 0;\n>  }\n\ncache.h (actually git-compat-util.h that cache.h includes) messes\naround with system headers by defining this and that macro. The\ngeneral rule is if cache.h or git-compat-util.h is included, it's the\nfirst #include, and system includes will be always in\ngit-compat-util.h (grep '^#include' shows this). Maybe it's best to\nleave this memcpy alone (and if you do, state so in the commit message\nwith the reason).\n-- \nDuy\n"},{"id":"235706","messageId":"CALUzUxo=5aUCjL0GDz=3JjuQqN4+9pTPbmNWO3Rda+UuLDOYhQ@mail.gmail.com","threadId":"36006","inReplyTo":"CACsJy8Apoz43HPAgdrTHSNgSOcUhv9j258+r0xDJeioY3iogig@mail.gmail.com","subject":"Re: [PATCH] Replace memcpy with hashcpy when dealing hash copy globally","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2014-03-01T09:13:50Z","receivedAt":"2014-03-01T09:13:50Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"On Sat, Mar 1, 2014 at 10:58 AM, Duy Nguyen <pclouds@gmail.com> wrote:\n> On Sat, Mar 1, 2014 at 8:07 AM, Sun He <sunheehnus@gmail.com> wrote:\n>> Signed-off-by: Sun He <sunheehnus@gmail.com>\n>> ---\n>>  Find the potential places with memcpy by the bash command:\n>>    $ find . | xargs grep \"memcpy.*\\(.*20.*\\)\"\n>>\n>>  Helped-by: Michael Haggerty<mhagger@alum.mit.edu>\n>\n> You may want to put this Helped-by before \"---\" because it's supposed\n> to end up in the final commit.\n\nTo elaborate further: anything below the three-dash is ignored when\nthe patch is applied. So it doesn't show up in the commit at all. I\ndon't really know the reason for this - probably a patch (1) thing.\n\nYou could put the patch the Helped-by before your Signed-off-by\n(sometimes referred to as S-o-b).\n\n-- \nCheers,\nRay Chuan\n"},{"id":"235749","messageId":"CAJr59C37x9pdjcpo_4MrRm8Zk+So2JUj3TjBOGH+Bj-La=RTwQ@mail.gmail.com","threadId":"36006","inReplyTo":"CACsJy8Apoz43HPAgdrTHSNgSOcUhv9j258+r0xDJeioY3iogig@mail.gmail.com","subject":"Re: [PATCH] Replace memcpy with hashcpy when dealing hash copy globally","fromName":"He Sun","fromEmail":"sunheehnus@gmail.com","sentAt":"2014-03-01T14:53:36Z","receivedAt":"2014-03-01T14:53:36Z","isPatch":true,"sender":{"key":"sunheehnus@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2889804?v=4"},"body":"2014-03-01 10:58 GMT+08:00 Duy Nguyen <pclouds@gmail.com>:\n> On Sat, Mar 1, 2014 at 8:07 AM, Sun He <sunheehnus@gmail.com> wrote:\n>> Signed-off-by: Sun He <sunheehnus@gmail.com>\n>> ---\n>>  Find the potential places with memcpy by the bash command:\n>>    $ find . | xargs grep \"memcpy.*\\(.*20.*\\)\"\n>>\n>>  Helped-by: Michael Haggerty<mhagger@alum.mit.edu>\n>\n> You may want to put this Helped-by before \"---\" because it's supposed\n> to end up in the final commit. The patch looks straightforward,\n> except..\n>\n\nYeah, got it.\nThanks.\n\n>> diff --git a/ppc/sha1.c b/ppc/sha1.c\n>> index ec6a192..8a87fea 100644\n>> --- a/ppc/sha1.c\n>> +++ b/ppc/sha1.c\n>> @@ -9,6 +9,7 @@\n>>  #include <stdio.h>\n>>  #include <string.h>\n>>  #include \"sha1.h\"\n>> +#include \"cache.h\"\n>>\n>>  extern void ppc_sha1_core(uint32_t *hash, const unsigned char *p,\n>>                           unsigned int nblocks);\n>> @@ -67,6 +68,6 @@ int ppc_SHA1_Final(unsigned char *hash, ppc_SHA_CTX *c)\n>>                 memset(&c->buf.b[cnt], 0, 56 - cnt);\n>>         c->buf.l[7] = c->len;\n>>         ppc_sha1_core(c->hash, c->buf.b, 1);\n>> -       memcpy(hash, c->hash, 20);\n>> +       hashcpy(hash, c->hash);\n>>         return 0;\n>>  }\n>\n> cache.h (actually git-compat-util.h that cache.h includes) messes\n> around with system headers by defining this and that macro. The\n> general rule is if cache.h or git-compat-util.h is included, it's the\n> first #include, and system includes will be always in\n> git-compat-util.h (grep '^#include' shows this). Maybe it's best to\n> leave this memcpy alone (and if you do, state so in the commit message\n> with the reason).\n\nYap, after I parsed all the sourcecode\n\nI have find out all the files that cache.h git-compat-util.h and\nbuiltin.h are not the first #include\n\n==> test-sigchain.c <==\n#include \"sigchain.h\"\n==> sigchain.c <==\n#include \"sigchain.h\"\n\nAnd I checked \"sigchain.h\", that it includes very little information.\nIt didn't import any potential errors. But I think it should be placed\nafter \"cache.h\" to match the consistence of the general rule.\n\n> --\n> Duy\n"},{"id":"235750","messageId":"CAJr59C2oi9Oi=SJMZigw4SnXnRmVG5wQOpWL2eeVv_u1bfKvmg@mail.gmail.com","threadId":"36006","inReplyTo":"CACsJy8Apoz43HPAgdrTHSNgSOcUhv9j258+r0xDJeioY3iogig@mail.gmail.com","subject":"Re: [PATCH] Replace memcpy with hashcpy when dealing hash copy globally","fromName":"He Sun","fromEmail":"sunheehnus@gmail.com","sentAt":"2014-03-01T14:53:45Z","receivedAt":"2014-03-01T14:53:45Z","isPatch":true,"sender":{"key":"sunheehnus@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2889804?v=4"},"body":"2014-03-01 10:58 GMT+08:00 Duy Nguyen <pclouds@gmail.com>:\n> On Sat, Mar 1, 2014 at 8:07 AM, Sun He <sunheehnus@gmail.com> wrote:\n>> Signed-off-by: Sun He <sunheehnus@gmail.com>\n>> ---\n>>  Find the potential places with memcpy by the bash command:\n>>    $ find . | xargs grep \"memcpy.*\\(.*20.*\\)\"\n>>\n>>  Helped-by: Michael Haggerty<mhagger@alum.mit.edu>\n>\n> You may want to put this Helped-by before \"---\" because it's supposed\n> to end up in the final commit. The patch looks straightforward,\n> except..\n>\n\nYeah, got it.\nThanks.\n\n>> diff --git a/ppc/sha1.c b/ppc/sha1.c\n>> index ec6a192..8a87fea 100644\n>> --- a/ppc/sha1.c\n>> +++ b/ppc/sha1.c\n>> @@ -9,6 +9,7 @@\n>>  #include <stdio.h>\n>>  #include <string.h>\n>>  #include \"sha1.h\"\n>> +#include \"cache.h\"\n>>\n>>  extern void ppc_sha1_core(uint32_t *hash, const unsigned char *p,\n>>                           unsigned int nblocks);\n>> @@ -67,6 +68,6 @@ int ppc_SHA1_Final(unsigned char *hash, ppc_SHA_CTX *c)\n>>                 memset(&c->buf.b[cnt], 0, 56 - cnt);\n>>         c->buf.l[7] = c->len;\n>>         ppc_sha1_core(c->hash, c->buf.b, 1);\n>> -       memcpy(hash, c->hash, 20);\n>> +       hashcpy(hash, c->hash);\n>>         return 0;\n>>  }\n>\n> cache.h (actually git-compat-util.h that cache.h includes) messes\n> around with system headers by defining this and that macro. The\n> general rule is if cache.h or git-compat-util.h is included, it's the\n> first #include, and system includes will be always in\n> git-compat-util.h (grep '^#include' shows this). Maybe it's best to\n> leave this memcpy alone (and if you do, state so in the commit message\n> with the reason).\n\nYap, I should follow the general rule. My fault.\nThanks.\n\nWhat's more,\n\nI have find out all the files that cache.h git-compat-util.h and\nbuiltin.h are not the first #include\n\n==> test-sigchain.c <==\n#include \"sigchain.h\"\n==> sigchain.c <==\n#include \"sigchain.h\"\n\nAnd I checked \"sigchain.h\", that it includes very little information.\nIt didn't import any potential errors. But I think it should be placed\nafter \"cache.h\" to match the consistence of the general rule.\n\n> --\n> Duy\n"},{"id":"235751","messageId":"CAJr59C3Lc_NrXNVT8aB9CThQRZvakBJWVVghf0M7S0z0qSN=DA@mail.gmail.com","threadId":"36006","inReplyTo":"CALUzUxo=5aUCjL0GDz=3JjuQqN4+9pTPbmNWO3Rda+UuLDOYhQ@mail.gmail.com","subject":"Re: [PATCH] Replace memcpy with hashcpy when dealing hash copy globally","fromName":"He Sun","fromEmail":"sunheehnus@gmail.com","sentAt":"2014-03-01T14:55:05Z","receivedAt":"2014-03-01T14:55:05Z","isPatch":true,"sender":{"key":"sunheehnus@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2889804?v=4"},"body":"Got it.\nThanks.\n\n2014-03-01 17:13 GMT+08:00 Tay Ray Chuan <rctay89@gmail.com>:\n> On Sat, Mar 1, 2014 at 10:58 AM, Duy Nguyen <pclouds@gmail.com> wrote:\n>> On Sat, Mar 1, 2014 at 8:07 AM, Sun He <sunheehnus@gmail.com> wrote:\n>>> Signed-off-by: Sun He <sunheehnus@gmail.com>\n>>> ---\n>>>  Find the potential places with memcpy by the bash command:\n>>>    $ find . | xargs grep \"memcpy.*\\(.*20.*\\)\"\n>>>\n>>>  Helped-by: Michael Haggerty<mhagger@alum.mit.edu>\n>>\n>> You may want to put this Helped-by before \"---\" because it's supposed\n>> to end up in the final commit.\n>\n> To elaborate further: anything below the three-dash is ignored when\n> the patch is applied. So it doesn't show up in the commit at all. I\n> don't really know the reason for this - probably a patch (1) thing.\n>\n> You could put the patch the Helped-by before your Signed-off-by\n> (sometimes referred to as S-o-b).\n>\n> --\n> Cheers,\n> Ray Chuan\n"}]}