* [PATCH] progress.c: avoid use of dynamic-sized array
@ 2008-06-08 15:26 Boyd Lynn Gerber
2008-06-08 19:30 ` Johannes Schindelin
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Boyd Lynn Gerber @ 2008-06-08 15:26 UTC (permalink / raw)
To: Git List
Dynamically sized arrays are gcc and C99 construct. Using them hurts
portability to older compilers, although using them is nice in this case
it is not desirable. This patch removes the only use of the construct
in stop_progress_msg(); the function is about writing out a single line
of a message, and the existing callers of this function feed messages
of only bounded size anyway, so use of dynamic array is simply overkill.
Signed-off-by: Boyd Lynn Gerber <gerberb@zenez.com>
--
Boyd Gerber <gerberb@zenez.com>
ZENEZ 1042 East Fort Union #135, Midvale Utah 84047
---
Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
---
progress.c
diff --git a/progress.c b/progress.c
index d19f80c..55a8687 100644
--- a/progress.c
+++ b/progress.c
@@ -241,16 +241,21 @@ void stop_progress_msg(struct progress **p_progress, const char *msg)
*p_progress = NULL;
if (progress->last_value != -1) {
/* Force the last update */
- char buf[strlen(msg) + 5];
+ char buf[128], *bufp;
+ size_t len = strlen(msg) + 5;
struct throughput *tp = progress->throughput;
+
+ bufp = (len < sizeof(buf)) ? buf : xmalloc(len + 1);
if (tp) {
unsigned int rate = !tp->avg_misecs ? 0 :
tp->avg_bytes / tp->avg_misecs;
throughput_string(tp, tp->curr_total, rate);
}
progress_update = 1;
- sprintf(buf, ", %s.\n", msg);
- display(progress, progress->last_value, buf);
+ sprintf(bufp, ", %s.\n", msg);
+ display(progress, progress->last_value, bufp);
+ if (buf != bufp)
+ free(bufp);
}
clear_progress_signal();
free(progress->throughput);
--
1.5.2.4
--
Boyd Gerber <gerberb@zenez.com>
ZENEZ 1042 East Fort Union #135, Midvale Utah 84047
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH] progress.c: avoid use of dynamic-sized array
2008-06-08 7:45 ` Junio C Hamano
@ 2008-06-08 16:57 ` Boyd Lynn Gerber
0 siblings, 0 replies; 9+ messages in thread
From: Boyd Lynn Gerber @ 2008-06-08 16:57 UTC (permalink / raw)
To: Junio C Hamano
Cc: Daniel Barkalow, Thomas Harning, Jeremy Maitin-Shepard, Git List
Dynamically sized arrays are gcc and C99 construct. Using them hurts
portability to older compilers, although using them is nice in this case
it is not desirable. This patch removes the only use of the construct
in stop_progress_msg(); the function is about writing out a single line
of a message, and the existing callers of this function feed messages
of only bounded size anyway, so use of dynamic array is simply overkill.
This is with suggestions and modifications from
Daniel Barkalow <barkalow@iabervon.org>
Junio C Hamano <gitster@pobox.com>
Thomas Harning <harningt@gmail.com>
Jeremy Maitin-Shepard <jbms@cmu.edu>
Signed-off-by: Boyd Lynn Gerber <gerberb@zenez.com>
--
Boyd Gerber <gerberb@zenez.com>
ZENEZ 1042 East Fort Union #135, Midvale Utah 84047
---
Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
---
progress.c
diff --git a/progress.c b/progress.c
index d19f80c..55a8687 100644
--- a/progress.c
+++ b/progress.c
@@ -241,16 +241,21 @@ void stop_progress_msg(struct progress **p_progress, const char *msg)
*p_progress = NULL;
if (progress->last_value != -1) {
/* Force the last update */
- char buf[strlen(msg) + 5];
+ char buf[128], *bufp;
+ size_t len = strlen(msg) + 5;
struct throughput *tp = progress->throughput;
+
+ bufp = (len < sizeof(buf)) ? buf : xmalloc(len + 1);
if (tp) {
unsigned int rate = !tp->avg_misecs ? 0 :
tp->avg_bytes / tp->avg_misecs;
throughput_string(tp, tp->curr_total, rate);
}
progress_update = 1;
- sprintf(buf, ", %s.\n", msg);
- display(progress, progress->last_value, buf);
+ sprintf(bufp, ", %s.\n", msg);
+ display(progress, progress->last_value, bufp);
+ if (buf != bufp)
+ free(bufp);
}
clear_progress_signal();
free(progress->throughput);
--
1.5.2.4
--
Boyd Gerber <gerberb@zenez.com>
ZENEZ 1042 East Fort Union #135, Midvale Utah 84047
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] progress.c: avoid use of dynamic-sized array
2008-06-08 15:26 [PATCH] progress.c: avoid use of dynamic-sized array Boyd Lynn Gerber
@ 2008-06-08 19:30 ` Johannes Schindelin
2008-06-08 19:52 ` Boyd Lynn Gerber
2008-06-08 21:34 ` Alex Riesen
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Johannes Schindelin @ 2008-06-08 19:30 UTC (permalink / raw)
To: Boyd Lynn Gerber; +Cc: Git List
Hi,
On Sun, 8 Jun 2008, Boyd Lynn Gerber wrote:
>
> Dynamically sized arrays are gcc and C99 construct. Using them hurts
> portability to older compilers, although using them is nice in this case
> it is not desirable. This patch removes the only use of the construct
> in stop_progress_msg(); the function is about writing out a single line
> of a message, and the existing callers of this function feed messages
> of only bounded size anyway, so use of dynamic array is simply overkill.
>
> Signed-off-by: Boyd Lynn Gerber <gerberb@zenez.com>
>
> --
> Boyd Gerber <gerberb@zenez.com>
> ZENEZ 1042 East Fort Union #135, Midvale Utah 84047
>
> ---
Do you really want to have your mail signature in the commit message,
particularly because...
> [...]
>
> clear_progress_signal();
> free(progress->throughput);
> --
> 1.5.2.4
>
>
> --
> Boyd Gerber <gerberb@zenez.com>
> ZENEZ 1042 East Fort Union #135, Midvale Utah 84047
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
You repeat it at the end of the mail anyway?
The patch looks fine to me, though.
Ciao,
Dscho
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] progress.c: avoid use of dynamic-sized array
2008-06-08 19:30 ` Johannes Schindelin
@ 2008-06-08 19:52 ` Boyd Lynn Gerber
0 siblings, 0 replies; 9+ messages in thread
From: Boyd Lynn Gerber @ 2008-06-08 19:52 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Git List
On Sun, 8 Jun 2008, Johannes Schindelin wrote:
> On Sun, 8 Jun 2008, Boyd Lynn Gerber wrote:
> > Dynamically sized arrays are gcc and C99 construct. Using them hurts
> > portability to older compilers, although using them is nice in this case
> > it is not desirable. This patch removes the only use of the construct
> > in stop_progress_msg(); the function is about writing out a single line
> > of a message, and the existing callers of this function feed messages
> > of only bounded size anyway, so use of dynamic array is simply overkill.
> >
> > Signed-off-by: Boyd Lynn Gerber <gerberb@zenez.com>
> >
> > --
> > Boyd Gerber <gerberb@zenez.com>
> > ZENEZ 1042 East Fort Union #135, Midvale Utah 84047
> >
> > ---
>
> Do you really want to have your mail signature in the commit message,
> particularly because...
>
> > [...]
> >
> > clear_progress_signal();
> > free(progress->throughput);
> > --
> > 1.5.2.4
> >
> >
> > --
> > Boyd Gerber <gerberb@zenez.com>
> > ZENEZ 1042 East Fort Union #135, Midvale Utah 84047
>
> You repeat it at the end of the mail anyway?
>
> The patch looks fine to me, though.
I put it in because in the git repo it is not their. Only in the email.
It is fine to remove it.
--
Boyd Gerber <gerberb@zenez.com>
ZENEZ 1042 East Fort Union #135, Midvale Utah 84047
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] progress.c: avoid use of dynamic-sized array
2008-06-08 15:26 [PATCH] progress.c: avoid use of dynamic-sized array Boyd Lynn Gerber
2008-06-08 19:30 ` Johannes Schindelin
@ 2008-06-08 21:34 ` Alex Riesen
2008-06-08 21:50 ` しらいしななこ
[not found] ` <200806082151.m58Lp6sH014324@mi0.bluebottle.com>
3 siblings, 0 replies; 9+ messages in thread
From: Alex Riesen @ 2008-06-08 21:34 UTC (permalink / raw)
To: Boyd Lynn Gerber; +Cc: Git List
Boyd Lynn Gerber, Sun, Jun 08, 2008 17:26:15 +0200:
> /* Force the last update */
> - char buf[strlen(msg) + 5];
> + char buf[128], *bufp;
> + size_t len = strlen(msg) + 5;
> struct throughput *tp = progress->throughput;
> +
> + bufp = (len < sizeof(buf)) ? buf : xmalloc(len + 1);
It is just a temporary buffer, there is no urgent need to
micro-optimize the allocation like that. Maybe just leave
one of the buffers, the one on stack? It is just a progress
message, snprintf will cut it, yes, but it is unlikely to
cause any harm (unless you forget to \n-terminate it).
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] progress.c: avoid use of dynamic-sized array
2008-06-08 21:19 ` Junio C Hamano
@ 2008-06-08 21:37 ` Boyd Lynn Gerber
0 siblings, 0 replies; 9+ messages in thread
From: Boyd Lynn Gerber @ 2008-06-08 21:37 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Jakub Narebski, Git List
Dynamically sized arrays are gcc and C99 construct. Using them hurts
portability to older compilers, although using them is nice in this case
it is not desirable. This patch removes the only use of the construct
in stop_progress_msg(); the function is about writing out a single line
of a message, and the existing callers of this function feed messages
of only bounded size anyway, so use of dynamic array is simply overkill.
This is with suggestions from
Daniel Barkalow <barkalow@iabervon.org>
Junio C Hamano <gitster@pobox.com>
Thomas Harning <harningt@gmail.com>
Jeremy Maitin-Shepard <jbms@cmu.edu>
Signed-off-by: Boyd Lynn Gerber <gerberb@zenez.com>
--
Boyd Gerber <gerberb@zenez.com>
ZENEZ 1042 East Fort Union #135, Midvale Utah 84047
---
Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
---
progress.c
Changes for older OS's that do not support the current methods for
allocation of memory.
diff --git a/progress.c b/progress.c
index d19f80c..55a8687 100644
--- a/progress.c
+++ b/progress.c
@@ -241,16 +241,21 @@ void stop_progress_msg(struct progress **p_progress, const char *msg)
*p_progress = NULL;
if (progress->last_value != -1) {
/* Force the last update */
- char buf[strlen(msg) + 5];
+ char buf[128], *bufp;
+ size_t len = strlen(msg) + 5;
struct throughput *tp = progress->throughput;
+
+ bufp = (len < sizeof(buf)) ? buf : xmalloc(len + 1);
if (tp) {
unsigned int rate = !tp->avg_misecs ? 0 :
tp->avg_bytes / tp->avg_misecs;
throughput_string(tp, tp->curr_total, rate);
}
progress_update = 1;
- sprintf(buf, ", %s.\n", msg);
- display(progress, progress->last_value, buf);
+ sprintf(bufp, ", %s.\n", msg);
+ display(progress, progress->last_value, bufp);
+ if (buf != bufp)
+ free(bufp);
}
clear_progress_signal();
free(progress->throughput);
--
1.5.2.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] progress.c: avoid use of dynamic-sized array
2008-06-08 15:26 [PATCH] progress.c: avoid use of dynamic-sized array Boyd Lynn Gerber
2008-06-08 19:30 ` Johannes Schindelin
2008-06-08 21:34 ` Alex Riesen
@ 2008-06-08 21:50 ` しらいしななこ
2008-06-08 22:02 ` Junio C Hamano
[not found] ` <200806082151.m58Lp6sH014324@mi0.bluebottle.com>
3 siblings, 1 reply; 9+ messages in thread
From: しらいしななこ @ 2008-06-08 21:50 UTC (permalink / raw)
To: Boyd Lynn Gerber; +Cc: Git List
Quoting Boyd Lynn Gerber <gerberb@zenez.com>:
> Dynamically sized arrays are gcc and C99 construct. Using them hurts
> portability to older compilers, although using them is nice in this case
> it is not desirable. This patch removes the only use of the construct
> in stop_progress_msg(); the function is about writing out a single line
> of a message, and the existing callers of this function feed messages
> of only bounded size anyway, so use of dynamic array is simply overkill.
>
> Signed-off-by: Boyd Lynn Gerber <gerberb@zenez.com>
I may be mistaken but isn't this Junio's patch? If so (quoting
from SubmittingPatches document):
If you are forwarding a patch from somebody else, optionally, at
the beginning of the e-mail message just before the commit
message starts, you can put a "From: " line to name that person.
--
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/
----------------------------------------------------------------------
Find out how you can get spam free email.
http://www.bluebottle.com/tag/3
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] progress.c: avoid use of dynamic-sized array
[not found] ` <200806082151.m58Lp6sH014324@mi0.bluebottle.com>
@ 2008-06-08 21:53 ` Boyd Lynn Gerber
0 siblings, 0 replies; 9+ messages in thread
From: Boyd Lynn Gerber @ 2008-06-08 21:53 UTC (permalink / raw)
To: しらいしななこ; +Cc: Git List
On Mon, 9 Jun 2008, しらいしななこ wrote:
> Quoting Boyd Lynn Gerber <gerberb@zenez.com>:
> > Dynamically sized arrays are gcc and C99 construct. Using them hurts
> > portability to older compilers, although using them is nice in this case
> > it is not desirable. This patch removes the only use of the construct
> > in stop_progress_msg(); the function is about writing out a single line
> > of a message, and the existing callers of this function feed messages
> > of only bounded size anyway, so use of dynamic array is simply overkill.
> >
> > Signed-off-by: Boyd Lynn Gerber <gerberb@zenez.com>
>
> I may be mistaken but isn't this Junio's patch? If so (quoting
> from SubmittingPatches document):
>
> If you are forwarding a patch from somebody else, optionally, at
> the beginning of the e-mail message just before the commit
> message starts, you can put a "From: " line to name that person.
It is his from my orignal modifications. I thought he suggested I make
the changes and resubmit it as a seperate patch. Thanks for the
clarifications.
--
Boyd Gerber <gerberb@zenez.com>
ZENEZ 1042 East Fort Union #135, Midvale Utah 84047
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] progress.c: avoid use of dynamic-sized array
2008-06-08 21:50 ` しらいしななこ
@ 2008-06-08 22:02 ` Junio C Hamano
0 siblings, 0 replies; 9+ messages in thread
From: Junio C Hamano @ 2008-06-08 22:02 UTC (permalink / raw)
To: しらいしななこ
Cc: Boyd Lynn Gerber, Git List
しらいしななこ <nanako3@bluebottle.com> writes:
> Quoting Boyd Lynn Gerber <gerberb@zenez.com>:
>
>> Dynamically sized arrays are gcc and C99 construct. Using them hurts
>> portability to older compilers, although using them is nice in this case
>> it is not desirable. This patch removes the only use of the construct
>> in stop_progress_msg(); the function is about writing out a single line
>> of a message, and the existing callers of this function feed messages
>> of only bounded size anyway, so use of dynamic array is simply overkill.
>>
>> Signed-off-by: Boyd Lynn Gerber <gerberb@zenez.com>
>
> I may be mistaken but isn't this Junio's patch? If so (quoting
> from SubmittingPatches document):
>
> If you are forwarding a patch from somebody else, optionally, at
> the beginning of the e-mail message just before the commit
> message starts, you can put a "From: " line to name that person.
Heh, thanks for being picky ;-)
Something this small, either way is fine by me. Besides, I've applied the
patch (and the other one) from Boyd already.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2008-06-08 22:03 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-08 15:26 [PATCH] progress.c: avoid use of dynamic-sized array Boyd Lynn Gerber
2008-06-08 19:30 ` Johannes Schindelin
2008-06-08 19:52 ` Boyd Lynn Gerber
2008-06-08 21:34 ` Alex Riesen
2008-06-08 21:50 ` しらいしななこ
2008-06-08 22:02 ` Junio C Hamano
[not found] ` <200806082151.m58Lp6sH014324@mi0.bluebottle.com>
2008-06-08 21:53 ` Boyd Lynn Gerber
-- strict thread matches above, loose matches on Subject: below --
2008-06-08 15:28 [PATCH] Port to 12 other Platforms Boyd Lynn Gerber
2008-06-08 15:46 ` Jakub Narebski
2008-06-08 16:04 ` Boyd Lynn Gerber
2008-06-08 18:52 ` Junio C Hamano
2008-06-08 20:47 ` Boyd Lynn Gerber
2008-06-08 21:19 ` Junio C Hamano
2008-06-08 21:37 ` [PATCH] progress.c: avoid use of dynamic-sized array Boyd Lynn Gerber
2008-06-06 19:34 [PATCH] This patch is to allow 12 different OS's to compile and run git Boyd Lynn Gerber
2008-06-06 19:39 ` Jeremy Maitin-Shepard
2008-06-06 20:02 ` Boyd Lynn Gerber
2008-06-06 23:08 ` Junio C Hamano
2008-06-06 23:23 ` Boyd Lynn Gerber
2008-06-07 0:38 ` [PATCH] 0002 " Boyd Lynn Gerber
2008-06-07 0:47 ` Daniel Barkalow
2008-06-07 1:25 ` [PATCH] 0003 " Boyd Lynn Gerber
2008-06-07 2:12 ` Junio C Hamano
2008-06-07 2:40 ` Boyd Lynn Gerber
2008-06-07 3:40 ` Daniel Barkalow
2008-06-08 3:46 ` Boyd Lynn Gerber
2008-06-08 7:45 ` Junio C Hamano
2008-06-08 16:57 ` [PATCH] progress.c: avoid use of dynamic-sized array Boyd Lynn Gerber
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox