{"thread":{"id":"10663","subject":"[PATCH] remove dead code from the csum-file interface","startedAt":"2007-11-05T03:54:50Z","lastAt":"2007-11-05T03:54:50Z","messageCount":1,"participants":["Nicolas Pitre"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"58345","messageId":"alpine.LFD.0.9999.0711042244310.21255@xanadu.home","threadId":"10663","inReplyTo":null,"subject":"[PATCH] remove dead code from the csum-file interface","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2007-11-05T03:54:50Z","receivedAt":"2007-11-05T03:54:50Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"The provided name argument is always constant and valid in every \ncaller's context, so no need to have an array of PATH_MAX chars to copy \nit into when a simple pointer will do.  Unfortunately that means getting \nrid of wascally wabbits too.\n\nThe 'error' field is also unused.\n\nSigned-off-by: Nicolas Pitre <nico@cam.org>\n---\ndiff --git a/csum-file.c b/csum-file.c\nindex b445e6a..9728a99 100644\n--- a/csum-file.c\n+++ b/csum-file.c\n@@ -88,22 +88,12 @@ struct sha1file *sha1fd(int fd, const char *name)\n \n struct sha1file *sha1fd_throughput(int fd, const char *name, struct progress *tp)\n {\n-\tstruct sha1file *f;\n-\tunsigned len;\n-\n-\tf = xmalloc(sizeof(*f));\n-\n-\tlen = strlen(name);\n-\tif (len >= PATH_MAX)\n-\t\tdie(\"you wascally wabbit, you\");\n-\tf->namelen = len;\n-\tmemcpy(f->name, name, len+1);\n-\n+\tstruct sha1file *f = xmalloc(sizeof(*f));\n \tf->fd = fd;\n-\tf->error = 0;\n \tf->offset = 0;\n \tf->total = 0;\n \tf->tp = tp;\n+\tf->name = name;\n \tf->do_crc = 0;\n \tSHA1_Init(&f->ctx);\n \treturn f;\ndiff --git a/csum-file.h b/csum-file.h\nindex a38cc3a..1af7656 100644\n--- a/csum-file.h\n+++ b/csum-file.h\n@@ -5,12 +5,12 @@ struct progress;\n \n /* A SHA1-protected file */\n struct sha1file {\n-\tint fd, error;\n-\tunsigned int offset, namelen;\n+\tint fd;\n+\tunsigned int offset;\n \tSHA_CTX ctx;\n \toff_t total;\n \tstruct progress *tp;\n-\tchar name[PATH_MAX];\n+\tconst char *name;\n \tint do_crc;\n \tuint32_t crc32;\n \tunsigned char buffer[8192];\n"}]}