{"thread":{"id":"735","subject":"[PATCH] Fix ptrdiff_t vs. int","startedAt":"2005-05-27T13:20:52Z","lastAt":"2005-05-29T20:21:52Z","messageCount":13,"participants":["Markus F.X.J. Oberhumer","Morten Welinder","Danjel McGougan","H. Peter Anvin","Linus Torvalds","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"4045","messageId":"42971EB4.2050403@oberhumer.com","threadId":"735","inReplyTo":null,"subject":"[PATCH] Fix ptrdiff_t vs. int","fromName":"Markus F.X.J. Oberhumer","fromEmail":"markus@oberhumer.com","sentAt":"2005-05-27T13:20:52Z","receivedAt":"2005-05-27T13:20:52Z","isPatch":true,"sender":{"key":"markus@oberhumer.com","avatar":null},"body":"This trivial patch fixes an obvious ptrdiff_t vs. int mismatch. Which\nmakes we wonder why Linus isn't hitting this on his ppc64 - maybe it's\ntime to start using -Werror...\n\nSigned-off-by: Markus F.X.J. Oberhumer <markus@oberhumer.com>\n\n-- \nMarkus Oberhumer, <markus@oberhumer.com>, http://www.oberhumer.com/\n\n\n\n\n\n\n\nThis trivial patch fixes an obvious ptrdiff_t vs. int mismatch.\n\nSigned-off-by: Markus F.X.J. Oberhumer <markus@oberhumer.com>\n\nIndex: diff-tree.c\n===================================================================\n--- 1348af9952a1d26b2ad14ec8f433322fd79510f3/diff-tree.c  (mode:100644)\n+++ 61dcf68d605a8d9204c24278dbdc73b4cf7ccc90/diff-tree.c  (mode:100644)\n@@ -274,7 +274,7 @@\n \t\t\tfor (cp = header; *cp; cp = ep) {\n \t\t\t\tep = strchr(cp, '\\n');\n \t\t\t\tif (ep == 0) ep = cp + strlen(cp);\n-\t\t\t\tprintf(\"%.*s%c\", ep-cp, cp, 0);\n+\t\t\t\tprintf(\"%.*s%c\", (int) (ep-cp), cp, 0);\n \t\t\t\tif (*ep) ep++;\n \t\t\t}\n \t\t}\n"},{"id":"4047","messageId":"d778gp$1er$1@sea.gmane.org","threadId":"735","inReplyTo":"42971EB4.2050403@oberhumer.com","subject":"Re: [PATCH] Fix ptrdiff_t vs. int","fromName":"Danjel McGougan","fromEmail":"danjel.mcgougan@comhem.se","sentAt":"2005-05-27T13:51:58Z","receivedAt":"2005-05-27T13:51:58Z","isPatch":true,"sender":{"key":"danjel.mcgougan@comhem.se","avatar":null},"body":"Markus F.X.J. Oberhumer wrote:\n> This trivial patch fixes an obvious ptrdiff_t vs. int mismatch. Which\n> makes we wonder why Linus isn't hitting this on his ppc64 - maybe it's\n> time to start using -Werror...\n> \n\nI think the PPC calling convention is to use registers for the first few \nparameters, so the bug probably will not surface on PPC64.\n\n/Danjel\n\n"},{"id":"4046","messageId":"118833cc05052707026a3dfedd@mail.gmail.com","threadId":"735","inReplyTo":"42971EB4.2050403@oberhumer.com","subject":"Re: [PATCH] Fix ptrdiff_t vs. int","fromName":"Morten Welinder","fromEmail":"mwelinder@gmail.com","sentAt":"2005-05-27T14:02:56Z","receivedAt":"2005-05-27T14:02:56Z","isPatch":true,"sender":{"key":"mwelinder@gmail.com","avatar":null},"body":"On 5/27/05, Markus F.X.J. Oberhumer <markus@oberhumer.com> wrote:\n> This trivial patch fixes an obvious ptrdiff_t vs. int mismatch. Which\n> makes we wonder why Linus isn't hitting this on his ppc64 - maybe it's\n> time to start using -Werror...\n\nThe best time to start using -Werror is \"never\".  Different compilers\n(and versions)\nwarn about different things, often affected by, say, optimization\nswitches.  Different\nsystem headers contain things that one compiler or another will issue a warning\nover.\n\nThus -Werror is solely for code that needs to work on one compiler, with one set\nof switches, with one libc version, and specific versions of included libraries.\n\nIt is tempting to submit a patch to the gcc people making -Werror issue a\nwarning about the trouble using -Werror.\n\nMorten\n"},{"id":"4052","messageId":"429749E6.2050806@zytor.com","threadId":"735","inReplyTo":"42971EB4.2050403@oberhumer.com","subject":"Re: [PATCH] Fix ptrdiff_t vs. int","fromName":"H. Peter Anvin","fromEmail":"hpa@zytor.com","sentAt":"2005-05-27T16:25:10Z","receivedAt":"2005-05-27T16:25:10Z","isPatch":true,"sender":{"key":"hpa@zytor.com","avatar":null},"body":"Markus F.X.J. Oberhumer wrote:\n> This trivial patch fixes an obvious ptrdiff_t vs. int mismatch. Which\n> makes we wonder why Linus isn't hitting this on his ppc64 - maybe it's\n> time to start using -Werror...\n\nThis doesn't affect CPUs with a register-based calling convention.\n\n\t-hpa\n"},{"id":"4055","messageId":"Pine.LNX.4.58.0505271013260.17402@ppc970.osdl.org","threadId":"735","inReplyTo":"42971EB4.2050403@oberhumer.com","subject":"Re: [PATCH] Fix ptrdiff_t vs. int","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-05-27T17:18:33Z","receivedAt":"2005-05-27T17:18:33Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Fri, 27 May 2005, Markus F.X.J. Oberhumer wrote:\n>\n> This trivial patch fixes an obvious ptrdiff_t vs. int mismatch. Which\n> makes we wonder why Linus isn't hitting this on his ppc64 - maybe it's\n> time to start using -Werror...\n\nMy _kernel_ is 64-bit, but my user-space is all 32-bit because (a) I don't\ncare about user-space and (b) I'm lazy and (c)  all the distributions\ncontain just 32-bit programs and a ppc64 kernel has no trouble running\n32-bit programs.\n\nI can compile a kernel with \"-m64\", but since I don't have any 64-bit\nlibraries installed, user space doesn't work that well ;)\n\n\t\tLinus\n"},{"id":"4056","messageId":"Pine.LNX.4.58.0505271024280.17402@ppc970.osdl.org","threadId":"735","inReplyTo":"Pine.LNX.4.58.0505271013260.17402@ppc970.osdl.org","subject":"Re: [PATCH] Fix ptrdiff_t vs. int","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-05-27T17:25:51Z","receivedAt":"2005-05-27T17:25:51Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Fri, 27 May 2005, Linus Torvalds wrote:\n> \n> I can compile a kernel with \"-m64\", but since I don't have any 64-bit\n> libraries installed, user space doesn't work that well ;)\n\nBtw, since this was the piece of code that I didn't bother simplifying \nlast time it was discussed (then it was just \"ugly\"), I took a different \napproach instead, and committed the following..\n\n\t\tLinus\n\n---\ndiff-tree 84c1afd7e7c69c6c3c0677d5ee01925d4c70d318 (from a9c9cef161b26ca610783dd0b180d18956c7b119)\nAuthor: Linus Torvalds <torvalds@ppc970.osdl.org>\nDate:   Fri May 27 10:22:09 2005 -0700\n    \n    git-diff-tree: simplify header output with '-z'\n    \n    No need to make them multiple lines, in fact we explicitly don't want that.\n    \n    This also fixes a 64-bit problem pointed out by Markus F.X.J. Oberhumer,\n    where we gave \"%.*s\" a \"ptrdiff_t\" length argument instead of an \"int\".\n\ndiff --git a/diff-tree.c b/diff-tree.c\n--- a/diff-tree.c\n+++ b/diff-tree.c\n@@ -269,18 +269,11 @@ static int call_diff_flush(void)\n \t\treturn 0;\n \t}\n \tif (header) {\n-\t\tif (diff_output_format == DIFF_FORMAT_MACHINE) {\n-\t\t\tconst char *ep, *cp;\n-\t\t\tfor (cp = header; *cp; cp = ep) {\n-\t\t\t\tep = strchr(cp, '\\n');\n-\t\t\t\tif (ep == 0) ep = cp + strlen(cp);\n-\t\t\t\tprintf(\"%.*s%c\", ep-cp, cp, 0);\n-\t\t\t\tif (*ep) ep++;\n-\t\t\t}\n-\t\t}\n-\t\telse {\n-\t\t\tprintf(\"%s\", header);\n-\t\t}\n+\t\tconst char *fmt = \"%s\";\n+\t\tif (diff_output_format == DIFF_FORMAT_MACHINE)\n+\t\t\tfmt = \"%s%c\";\n+\t\t\n+\t\tprintf(fmt, header, 0);\n \t\theader = NULL;\n \t}\n \tdiff_flush(diff_output_format, 1);\n"},{"id":"4059","messageId":"42975C1F.8070102@oberhumer.com","threadId":"735","inReplyTo":"Pine.LNX.4.58.0505271024280.17402@ppc970.osdl.org","subject":"Re: [PATCH] Fix ptrdiff_t vs. int","fromName":"Markus F.X.J. Oberhumer","fromEmail":"markus@oberhumer.com","sentAt":"2005-05-27T17:42:55Z","receivedAt":"2005-05-27T17:42:55Z","isPatch":true,"sender":{"key":"markus@oberhumer.com","avatar":null},"body":"Linus Torvalds wrote:\n> \n> On Fri, 27 May 2005, Linus Torvalds wrote:\n> \n>>I can compile a kernel with \"-m64\", but since I don't have any 64-bit\n>>libraries installed, user space doesn't work that well ;)\n> \n> \n> Btw, since this was the piece of code that I didn't bother simplifying \n> last time it was discussed (then it was just \"ugly\"), I took a different \n> approach instead, and committed the following..\n\nMany thanks. BTW, this is probably completely irrelevant on all \nreal-world machines and calling conventions, but still, lying on the \nnumber of arguments in vararg-functions is not my favourite practice.\n\n~Markus\n\n> \n> \t\tLinus\n> \n> ---\n> diff-tree 84c1afd7e7c69c6c3c0677d5ee01925d4c70d318 (from a9c9cef161b26ca610783dd0b180d18956c7b119)\n> Author: Linus Torvalds <torvalds@ppc970.osdl.org>\n> Date:   Fri May 27 10:22:09 2005 -0700\n>     \n>     git-diff-tree: simplify header output with '-z'\n>     \n>     No need to make them multiple lines, in fact we explicitly don't want that.\n>     \n>     This also fixes a 64-bit problem pointed out by Markus F.X.J. Oberhumer,\n>     where we gave \"%.*s\" a \"ptrdiff_t\" length argument instead of an \"int\".\n> \n> diff --git a/diff-tree.c b/diff-tree.c\n> --- a/diff-tree.c\n> +++ b/diff-tree.c\n> @@ -269,18 +269,11 @@ static int call_diff_flush(void)\n>  \t\treturn 0;\n>  \t}\n>  \tif (header) {\n> -\t\tif (diff_output_format == DIFF_FORMAT_MACHINE) {\n> -\t\t\tconst char *ep, *cp;\n> -\t\t\tfor (cp = header; *cp; cp = ep) {\n> -\t\t\t\tep = strchr(cp, '\\n');\n> -\t\t\t\tif (ep == 0) ep = cp + strlen(cp);\n> -\t\t\t\tprintf(\"%.*s%c\", ep-cp, cp, 0);\n> -\t\t\t\tif (*ep) ep++;\n> -\t\t\t}\n> -\t\t}\n> -\t\telse {\n> -\t\t\tprintf(\"%s\", header);\n> -\t\t}\n> +\t\tconst char *fmt = \"%s\";\n> +\t\tif (diff_output_format == DIFF_FORMAT_MACHINE)\n> +\t\t\tfmt = \"%s%c\";\n> +\t\t\n> +\t\tprintf(fmt, header, 0);\n>  \t\theader = NULL;\n>  \t}\n>  \tdiff_flush(diff_output_format, 1);\n> -\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n> \n\n\n-- \nMarkus Oberhumer, <markus@oberhumer.com>, http://www.oberhumer.com/\n"},{"id":"4062","messageId":"42975FDD.9050901@zytor.com","threadId":"735","inReplyTo":"42975C1F.8070102@oberhumer.com","subject":"Re: [PATCH] Fix ptrdiff_t vs. int","fromName":"H. Peter Anvin","fromEmail":"hpa@zytor.com","sentAt":"2005-05-27T17:58:53Z","receivedAt":"2005-05-27T17:58:53Z","isPatch":true,"sender":{"key":"hpa@zytor.com","avatar":null},"body":"Markus F.X.J. Oberhumer wrote:\n> \n> Many thanks. BTW, this is probably completely irrelevant on all \n> real-world machines and calling conventions, but still, lying on the \n> number of arguments in vararg-functions is not my favourite practice.\n> \n\nBullshit.\n\nThink about the way stdarg works, and you should quickly figure out that \nit is perfectly safe to pass extra arguments.\n\nHowever, this code can also be rewritten:\n\n\tfputs(header, stdout);\n\tif (diff_output_format == DIFF_FORMAT_MACHINE)\n\t\tputchar('\\0');\n\n... which is probably faster anyway.\n\n\t-hpa\n"},{"id":"4063","messageId":"Pine.LNX.4.58.0505271112240.17402@ppc970.osdl.org","threadId":"735","inReplyTo":"42975C1F.8070102@oberhumer.com","subject":"Re: [PATCH] Fix ptrdiff_t vs. int","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-05-27T18:13:27Z","receivedAt":"2005-05-27T18:13:27Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Fri, 27 May 2005, Markus F.X.J. Oberhumer wrote:\n> \n> Many thanks. BTW, this is probably completely irrelevant on all \n> real-world machines and calling conventions, but still, lying on the \n> number of arguments in vararg-functions is not my favourite practice.\n\nOnly using a subset is guaranteed to work - it's not about \"real-world \nmachines\", it's about the fact that it's not a C compiler any more if it \ndoesn't work.\n\n\t\tLinus\n"},{"id":"4066","messageId":"7vfyw8zg1w.fsf@assigned-by-dhcp.cox.net","threadId":"735","inReplyTo":"Pine.LNX.4.58.0505271024280.17402@ppc970.osdl.org","subject":"Re: [PATCH] Fix ptrdiff_t vs. int","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-27T18:20:43Z","receivedAt":"2005-05-27T18:20:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":">>>>> \"LT\" == Linus Torvalds <torvalds@osdl.org> writes:\n\nLT> On Fri, 27 May 2005, Linus Torvalds wrote:\n>> \n>> I can compile a kernel with \"-m64\", but since I don't have any 64-bit\n>> libraries installed, user space doesn't work that well ;)\n\nLT> Btw, since this was the piece of code that I didn't bother simplifying \nLT> last time it was discussed (then it was just \"ugly\"), I took a different \nLT> approach instead, and committed the following..\n\nI thought about this after getting your \"Your solution is the\nyucky one\" message, but make sure that you are not adding an\nextra blank line when this is combined with diff-helper.  I\nthink you currently do.\n\n"},{"id":"4123","messageId":"7vvf54xael.fsf_-_@assigned-by-dhcp.cox.net","threadId":"735","inReplyTo":"7vfyw8zg1w.fsf@assigned-by-dhcp.cox.net","subject":"[PATCH] Adjust diff-helper to diff-tree -v -z changes.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-28T04:05:38Z","receivedAt":"2005-05-28T04:05:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The latest change to diff-tree -z output adds an extra line\ntermination after non diff-raw material (the header and the\ncommit message).  To compensate for this change, stop adding the\noutput termination of our own.  \"diff-tree -v -z\" piped to\n\"diff-helper -z\" would give different result from \"diff-tree -v\"\npiped to \"diff-helper\" without this change.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\ndiff-helper.c |    5 ++++-\n1 files changed, 4 insertions(+), 1 deletion(-)\n\ndiff --git a/diff-helper.c b/diff-helper.c\n--- a/diff-helper.c\n+++ b/diff-helper.c\n@@ -15,6 +15,7 @@ static const char *diff_helper_usage =\n \n int main(int ac, const char **av) {\n \tstruct strbuf sb;\n+\tconst char *garbage_flush_format;\n \n \tstrbuf_init(&sb);\n \n@@ -30,6 +31,8 @@ int main(int ac, const char **av) {\n \t\t\tusage(diff_helper_usage);\n \t\tac--; av++;\n \t}\n+\tgarbage_flush_format = (line_termination == 0) ? \"%s\" : \"%s\\n\";\n+\n \t/* the remaining parameters are paths patterns */\n \n \tdiff_setup(0);\n@@ -134,7 +137,7 @@ int main(int ac, const char **av) {\n \t\tif (pickaxe)\n \t\t\tdiffcore_pickaxe(pickaxe, pickaxe_opts);\n \t\tdiff_flush(DIFF_FORMAT_PATCH, 0);\n-\t\tprintf(\"%s\\n\", sb.buf);\n+\t\tprintf(garbage_flush_format, sb.buf);\n \t}\n \tif (1 < ac)\n \t\tdiffcore_pathspec(av + 1);\n------------------------------------------------\n\n"},{"id":"4181","messageId":"Pine.LNX.4.58.0505291129520.10545@ppc970.osdl.org","threadId":"735","inReplyTo":"7vvf54xael.fsf_-_@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Adjust diff-helper to diff-tree -v -z changes.","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-05-29T18:31:05Z","receivedAt":"2005-05-29T18:31:05Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Fri, 27 May 2005, Junio C Hamano wrote:\n>\n> The latest change to diff-tree -z output adds an extra line\n> termination after non diff-raw material (the header and the\n> commit message).  To compensate for this change, stop adding the\n> output termination of our own.  \"diff-tree -v -z\" piped to\n> \"diff-helper -z\" would give different result from \"diff-tree -v\"\n> piped to \"diff-helper\" without this change.\n\nI think this is really a bug in your \"read_line()\" interface.\n\nYou should include the terminating character in the line count.\n\nThis also fixes and simplifies \"EOF\" handling.\n\n\t\tLinus\n"},{"id":"4192","messageId":"7vmzqdlr4v.fsf@assigned-by-dhcp.cox.net","threadId":"735","inReplyTo":"Pine.LNX.4.58.0505291129520.10545@ppc970.osdl.org","subject":"Re: [PATCH] Adjust diff-helper to diff-tree -v -z changes.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-29T20:21:52Z","receivedAt":"2005-05-29T20:21:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":">>>>> \"LT\" == Linus Torvalds <torvalds@osdl.org> writes:\n\nLT> I think this is really a bug in your \"read_line()\" interface.\nLT> You should include the terminating character in the line count.\n\nWhat the patch changed:\n\n    You give me a non diff-raw material \"foo\\nbar\\n\" when you\n    are not doing -z.  I read that without -z.  read_line()\n    drops the EOL so I get \"foo\" and \"bar\" on separate lines,\n    both of which I spit out with my own '\\n' using \"%s\\n\".\n\n    You give me \"foo\\nbar\\n\\0\" to express the same under -z, and\n    I read that with -z.  I get \"foo\\nbar\\n\" after read_line()\n    drops the EOL.  I should spit it out without my own '\\n',\n    i.e. not using \"%s\\n\" but \"%s\".\n\nIf read_line() interface changes to include EOL, then...\n\n    You give me \"foo\\nbar\\n\" without -z.  I read that without\n    -z.  Fixed read_line() retains the EOL and I get \"foo\\n\" and\n    \"bar\\n\", and I do not have to add my own '\\n' anymore; I\n    just do fputs().\n\n    You give me \"foo\\nbar\\n\\0\" under -z, and I read that with\n    -z.  Fixed read_line() retains the EOL so I get\n    \"foo\\nbar\\n\\0\".  I just do fputs() and it would drop the\n    '\\0'.\n\nWhat the last sentence does feels a bit hacky, but does the\nright thing.  It's a good fix.\n\nPlease discard the patch you are responding to unless you\nalready have applied it.\n\n\n\n"}]}