{"thread":{"id":"13864","subject":"[PATCH] progress.c: avoid use of dynamic-sized array","startedAt":"2008-06-08T15:26:15Z","lastAt":"2008-06-08T22:02:16Z","messageCount":7,"participants":["Boyd Lynn Gerber","Johannes Schindelin","Alex Riesen","しらいしななこ","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"79122","messageId":"Pine.LNX.4.64.0806080924330.18454@xenau.zenez.com","threadId":"13864","inReplyTo":null,"subject":"[PATCH] progress.c: avoid use of dynamic-sized array","fromName":"Boyd Lynn Gerber","fromEmail":"gerberb@zenez.com","sentAt":"2008-06-08T15:26:15Z","receivedAt":"2008-06-08T15:26:15Z","isPatch":true,"sender":{"key":"gerberb@zenez.com","avatar":null},"body":"\nDynamically sized arrays are gcc and C99 construct.  Using them hurts\nportability to older compilers, although using them is nice in this case\nit is not desirable.  This patch removes the only use of the construct\nin stop_progress_msg(); the function is about writing out a single line\nof a message, and the existing callers of this function feed messages\nof only bounded size anyway, so use of dynamic array is simply overkill.\n\nSigned-off-by: Boyd Lynn Gerber <gerberb@zenez.com>\n\n--\nBoyd Gerber <gerberb@zenez.com>\nZENEZ\t1042 East Fort Union #135, Midvale Utah  84047\n\n---\n        Developer's Certificate of Origin 1.1\n\n        By making a contribution to this project, I certify that:\n\n        (a) The contribution was created in whole or in part by me and I\n            have the right to submit it under the open source license\n            indicated in the file; or\n\n        (b) The contribution is based upon previous work that, to the best\n            of my knowledge, is covered under an appropriate open source\n            license and I have the right under that license to submit that\n            work with modifications, whether created in whole or in part\n            by me, under the same open source license (unless I am\n            permitted to submit under a different license), as indicated\n            in the file; or\n\n        (c) The contribution was provided directly to me by some other\n            person who certified (a), (b) or (c) and I have not modified\n            it.\n\n        (d) I understand and agree that this project and the contribution\n            are public and that a record of the contribution (including all\n            personal information I submit with it, including my sign-off) is\n            maintained indefinitely and may be redistributed consistent with\n            this project or the open source license(s) involved.\n\n---\nprogress.c\n\ndiff --git a/progress.c b/progress.c\nindex d19f80c..55a8687 100644\n--- a/progress.c\n+++ b/progress.c\n@@ -241,16 +241,21 @@ void stop_progress_msg(struct progress **p_progress, const char *msg)\n \t*p_progress = NULL;\n \tif (progress->last_value != -1) {\n \t\t/* Force the last update */\n-\t\tchar buf[strlen(msg) + 5];\n+\t\tchar buf[128], *bufp;\n+\t\tsize_t len = strlen(msg) + 5;\n \t\tstruct throughput *tp = progress->throughput;\n+\n+\t\tbufp = (len < sizeof(buf)) ? buf : xmalloc(len + 1);\n \t\tif (tp) {\n \t\t\tunsigned int rate = !tp->avg_misecs ? 0 :\n \t\t\t\t\ttp->avg_bytes / tp->avg_misecs;\n \t\t\tthroughput_string(tp, tp->curr_total, rate);\n \t\t}\n \t\tprogress_update = 1;\n-\t\tsprintf(buf, \", %s.\\n\", msg);\n-\t\tdisplay(progress, progress->last_value, buf);\n+\t\tsprintf(bufp, \", %s.\\n\", msg);\n+\t\tdisplay(progress, progress->last_value, bufp);\n+\t\tif (buf != bufp)\n+\t\t\tfree(bufp);\n \t}\n \tclear_progress_signal();\n \tfree(progress->throughput);\n-- \n1.5.2.4\n\n\n--\nBoyd Gerber <gerberb@zenez.com>\nZENEZ\t1042 East Fort Union #135, Midvale Utah  84047\n"},{"id":"79153","messageId":"alpine.DEB.1.00.0806082029170.1783@racer","threadId":"13864","inReplyTo":"Pine.LNX.4.64.0806080924330.18454@xenau.zenez.com","subject":"Re: [PATCH] progress.c: avoid use of dynamic-sized array","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-06-08T19:30:48Z","receivedAt":"2008-06-08T19:30:48Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 8 Jun 2008, Boyd Lynn Gerber wrote:\n\n> \n> Dynamically sized arrays are gcc and C99 construct.  Using them hurts\n> portability to older compilers, although using them is nice in this case\n> it is not desirable.  This patch removes the only use of the construct\n> in stop_progress_msg(); the function is about writing out a single line\n> of a message, and the existing callers of this function feed messages\n> of only bounded size anyway, so use of dynamic array is simply overkill.\n> \n> Signed-off-by: Boyd Lynn Gerber <gerberb@zenez.com>\n> \n> --\n> Boyd Gerber <gerberb@zenez.com>\n> ZENEZ\t1042 East Fort Union #135, Midvale Utah  84047\n> \n> ---\n\nDo you really want to have your mail signature in the commit message, \nparticularly because...\n\n> [...]\n>\n>  \tclear_progress_signal();\n>  \tfree(progress->throughput);\n> -- \n> 1.5.2.4\n> \n> \n> --\n> Boyd Gerber <gerberb@zenez.com>\n> ZENEZ\t1042 East Fort Union #135, Midvale Utah  84047\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\nYou repeat it at the end of the mail anyway?\n\nThe patch looks fine to me, though.\n\nCiao,\nDscho\n"},{"id":"79154","messageId":"Pine.LNX.4.64.0806081351220.18454@xenau.zenez.com","threadId":"13864","inReplyTo":"alpine.DEB.1.00.0806082029170.1783@racer","subject":"Re: [PATCH] progress.c: avoid use of dynamic-sized array","fromName":"Boyd Lynn Gerber","fromEmail":"gerberb@zenez.com","sentAt":"2008-06-08T19:52:42Z","receivedAt":"2008-06-08T19:52:42Z","isPatch":true,"sender":{"key":"gerberb@zenez.com","avatar":null},"body":"On Sun, 8 Jun 2008, Johannes Schindelin wrote:\n> On Sun, 8 Jun 2008, Boyd Lynn Gerber wrote:\n> > Dynamically sized arrays are gcc and C99 construct.  Using them hurts\n> > portability to older compilers, although using them is nice in this case\n> > it is not desirable.  This patch removes the only use of the construct\n> > in stop_progress_msg(); the function is about writing out a single line\n> > of a message, and the existing callers of this function feed messages\n> > of only bounded size anyway, so use of dynamic array is simply overkill.\n> > \n> > Signed-off-by: Boyd Lynn Gerber <gerberb@zenez.com>\n> > \n> > --\n> > Boyd Gerber <gerberb@zenez.com>\n> > ZENEZ\t1042 East Fort Union #135, Midvale Utah  84047\n> > \n> > ---\n> \n> Do you really want to have your mail signature in the commit message, \n> particularly because...\n> \n> > [...]\n> >\n> >  \tclear_progress_signal();\n> >  \tfree(progress->throughput);\n> > -- \n> > 1.5.2.4\n> > \n> > \n> > --\n> > Boyd Gerber <gerberb@zenez.com>\n> > ZENEZ\t1042 East Fort Union #135, Midvale Utah  84047\n> \n> You repeat it at the end of the mail anyway?\n> \n> The patch looks fine to me, though.\n\nI put it in because in the git repo it is not their.  Only in the email.  \nIt is fine to remove it.\n\n--\nBoyd Gerber <gerberb@zenez.com>\nZENEZ\t1042 East Fort Union #135, Midvale Utah  84047\n"},{"id":"79167","messageId":"20080608213438.GA3073@steel.home","threadId":"13864","inReplyTo":"Pine.LNX.4.64.0806080924330.18454@xenau.zenez.com","subject":"Re: [PATCH] progress.c: avoid use of dynamic-sized array","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2008-06-08T21:34:38Z","receivedAt":"2008-06-08T21:34:38Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Boyd Lynn Gerber, Sun, Jun 08, 2008 17:26:15 +0200:\n>  \t\t/* Force the last update */\n> -\t\tchar buf[strlen(msg) + 5];\n> +\t\tchar buf[128], *bufp;\n> +\t\tsize_t len = strlen(msg) + 5;\n>  \t\tstruct throughput *tp = progress->throughput;\n> +\n> +\t\tbufp = (len < sizeof(buf)) ? buf : xmalloc(len + 1);\n\nIt is just a temporary buffer, there is no urgent need to\nmicro-optimize the allocation like that. Maybe just leave\none of the buffers, the one on stack? It is just a progress\nmessage, snprintf will cut it, yes, but it is unlikely to\ncause any harm (unless you forget to \\n-terminate it).\n"},{"id":"79171","messageId":"200806082151.m58Lp6sG014324@mi0.bluebottle.com","threadId":"13864","inReplyTo":"Pine.LNX.4.64.0806080924330.18454@xenau.zenez.com","subject":"Re: [PATCH] progress.c: avoid use of dynamic-sized array","fromName":"しらいしななこ","fromEmail":"nanako3@bluebottle.com","sentAt":"2008-06-08T21:50:18Z","receivedAt":"2008-06-08T21:50:18Z","isPatch":true,"sender":{"key":"nanako3@lavabit.com","avatar":"https://gravatar.com/avatar/3777b9e201c5883a62b1a6fdf7c53f2d712d1d80989146063ea861e33aad72a8?d=mp&s=160"},"body":"Quoting Boyd Lynn Gerber <gerberb@zenez.com>:\n\n> Dynamically sized arrays are gcc and C99 construct.  Using them hurts\n> portability to older compilers, although using them is nice in this case\n> it is not desirable.  This patch removes the only use of the construct\n> in stop_progress_msg(); the function is about writing out a single line\n> of a message, and the existing callers of this function feed messages\n> of only bounded size anyway, so use of dynamic array is simply overkill.\n>\n> Signed-off-by: Boyd Lynn Gerber <gerberb@zenez.com>\n\nI may be mistaken but isn't this Junio's patch?  If so (quoting\nfrom SubmittingPatches document):\n\n  If you are forwarding a patch from somebody else, optionally, at\n  the beginning of the e-mail message just before the commit\n  message starts, you can put a \"From: \" line to name that person.\n\n-- \nNanako Shiraishi\nhttp://ivory.ap.teacup.com/nanako3/\n\n----------------------------------------------------------------------\nFind out how you can get spam free email.\nhttp://www.bluebottle.com/tag/3\n"},{"id":"79172","messageId":"Pine.LNX.4.64.0806081551440.18454@xenau.zenez.com","threadId":"13864","inReplyTo":"200806082151.m58Lp6sH014324@mi0.bluebottle.com","subject":"Re: [PATCH] progress.c: avoid use of dynamic-sized array","fromName":"Boyd Lynn Gerber","fromEmail":"gerberb@zenez.com","sentAt":"2008-06-08T21:53:13Z","receivedAt":"2008-06-08T21:53:13Z","isPatch":true,"sender":{"key":"gerberb@zenez.com","avatar":null},"body":"On Mon, 9 Jun 2008, しらいしななこ wrote:\n> Quoting Boyd Lynn Gerber <gerberb@zenez.com>:\n> > Dynamically sized arrays are gcc and C99 construct.  Using them hurts\n> > portability to older compilers, although using them is nice in this case\n> > it is not desirable.  This patch removes the only use of the construct\n> > in stop_progress_msg(); the function is about writing out a single line\n> > of a message, and the existing callers of this function feed messages\n> > of only bounded size anyway, so use of dynamic array is simply overkill.\n> >\n> > Signed-off-by: Boyd Lynn Gerber <gerberb@zenez.com>\n> \n> I may be mistaken but isn't this Junio's patch?  If so (quoting\n> from SubmittingPatches document):\n> \n>   If you are forwarding a patch from somebody else, optionally, at\n>   the beginning of the e-mail message just before the commit\n>   message starts, you can put a \"From: \" line to name that person.\n\nIt is his from my orignal modifications.  I thought he suggested I make \nthe changes and resubmit it as a seperate patch.  Thanks for the \nclarifications.\n\n--\nBoyd Gerber <gerberb@zenez.com>\nZENEZ\t1042 East Fort Union #135, Midvale Utah  84047\n"},{"id":"79173","messageId":"7vve0jh9g7.fsf@gitster.siamese.dyndns.org","threadId":"13864","inReplyTo":"200806082151.m58Lp6sG014324@mi0.bluebottle.com","subject":"Re: [PATCH] progress.c: avoid use of dynamic-sized array","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-06-08T22:02:16Z","receivedAt":"2008-06-08T22:02:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"しらいしななこ  <nanako3@bluebottle.com> writes:\n\n> Quoting Boyd Lynn Gerber <gerberb@zenez.com>:\n>\n>> Dynamically sized arrays are gcc and C99 construct.  Using them hurts\n>> portability to older compilers, although using them is nice in this case\n>> it is not desirable.  This patch removes the only use of the construct\n>> in stop_progress_msg(); the function is about writing out a single line\n>> of a message, and the existing callers of this function feed messages\n>> of only bounded size anyway, so use of dynamic array is simply overkill.\n>>\n>> Signed-off-by: Boyd Lynn Gerber <gerberb@zenez.com>\n>\n> I may be mistaken but isn't this Junio's patch?  If so (quoting\n> from SubmittingPatches document):\n>\n>   If you are forwarding a patch from somebody else, optionally, at\n>   the beginning of the e-mail message just before the commit\n>   message starts, you can put a \"From: \" line to name that person.\n\nHeh, thanks for being picky ;-)\n\nSomething this small, either way is fine by me.  Besides, I've applied the\npatch (and the other one) from Boyd already.\n"}]}