git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH v3 0/2] Fix l10n
@ 2017-02-16 23:32 Maxim Moseychuk
  2017-02-16 23:32 ` [PATCH v3 1/2] bisect_next_all(): fix bisect crash when used the gettext translation Maxim Moseychuk
  2017-02-16 23:32 ` [PATCH v3 2/2] stop_progress_msg(): simplification function Maxim Moseychuk
  0 siblings, 2 replies; 3+ messages in thread
From: Maxim Moseychuk @ 2017-02-16 23:32 UTC (permalink / raw)
  To: git; +Cc: peff, jonathantanmy, Maxim Moseychuk

In some places fixed-size buffers can't store formatted string.
If it be happen then git die.

Jonathan Tan, Jeff King thanks a lot for your help.
This is really my first patches. Your help is invaluable.

Maxim Moseychuk (2):
  bisect_next_all(): fix bisect crash when used the gettext translation
  stop_progress_msg(): simplification function

 bisect.c   |  9 +++++----
 progress.c | 11 ++++-------
 2 files changed, 9 insertions(+), 11 deletions(-)

--
2.11.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v3 1/2] bisect_next_all(): fix bisect crash when used the gettext translation
  2017-02-16 23:32 [PATCH v3 0/2] Fix l10n Maxim Moseychuk
@ 2017-02-16 23:32 ` Maxim Moseychuk
  2017-02-16 23:32 ` [PATCH v3 2/2] stop_progress_msg(): simplification function Maxim Moseychuk
  1 sibling, 0 replies; 3+ messages in thread
From: Maxim Moseychuk @ 2017-02-16 23:32 UTC (permalink / raw)
  To: git; +Cc: peff, jonathantanmy, Maxim Moseychuk

The buffer steps_msg[32] is too small.
Translated "(roughly %d step)" string can not be located in the buffer.

Solution: using xstrfmt which dynamically allocates memory.

Dummy solution: just increase steps_msg size but is not safe.
That feels pretty hacky, though. In practice the set of translations is
contained, but it doesn't have to be (and certainly nobody would notice
if a new translation was added with a longer name until a user
complained).

Reproduce bug: "LANG=ru_RU.UTF8 git bisect start v4.9 v4.8" on linux sources.

Signed-off-by: Maxim Moseychuk <franchesko.salias.hudro.pedros@gmail.com>
---
 bisect.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/bisect.c b/bisect.c
index 21bc6daa4..787543cad 100644
--- a/bisect.c
+++ b/bisect.c
@@ -940,7 +940,7 @@ int bisect_next_all(const char *prefix, int no_checkout)
 	struct commit_list *tried;
 	int reaches = 0, all = 0, nr, steps;
 	const unsigned char *bisect_rev;
-	char steps_msg[32];
+	char *steps_msg;
 
 	read_bisect_terms(&term_bad, &term_good);
 	if (read_bisect_refs())
@@ -990,14 +990,15 @@ int bisect_next_all(const char *prefix, int no_checkout)
 
 	nr = all - reaches - 1;
 	steps = estimate_bisect_steps(all);
-	xsnprintf(steps_msg, sizeof(steps_msg),
-		  Q_("(roughly %d step)", "(roughly %d steps)", steps),
-		  steps);
+
+	steps_msg = xstrfmt(Q_("(roughly %d step)", "(roughly %d steps)",
+		  steps), steps);
 	/* TRANSLATORS: the last %s will be replaced with
 	   "(roughly %d steps)" translation */
 	printf(Q_("Bisecting: %d revision left to test after this %s\n",
 		  "Bisecting: %d revisions left to test after this %s\n",
 		  nr), nr, steps_msg);
+	free(steps_msg);
 
 	return bisect_checkout(bisect_rev, no_checkout);
 }
-- 
2.11.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v3 2/2] stop_progress_msg(): simplification function
  2017-02-16 23:32 [PATCH v3 0/2] Fix l10n Maxim Moseychuk
  2017-02-16 23:32 ` [PATCH v3 1/2] bisect_next_all(): fix bisect crash when used the gettext translation Maxim Moseychuk
@ 2017-02-16 23:32 ` Maxim Moseychuk
  1 sibling, 0 replies; 3+ messages in thread
From: Maxim Moseychuk @ 2017-02-16 23:32 UTC (permalink / raw)
  To: git; +Cc: peff, jonathantanmy, Maxim Moseychuk

stop_progress_msg() is rarely used and is not demanding to
performance. Use dynamically allocates memory.

Signed-off-by: Maxim Moseychuk <franchesko.salias.hudro.pedros@gmail.com>
---
 progress.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/progress.c b/progress.c
index 76a88c573..29378caa0 100644
--- a/progress.c
+++ b/progress.c
@@ -243,21 +243,18 @@ 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[128], *bufp;
-		size_t len = strlen(msg) + 5;
+		char *buf;
 		struct throughput *tp = progress->throughput;
 
-		bufp = (len < sizeof(buf)) ? buf : xmallocz(len);
 		if (tp) {
 			unsigned int rate = !tp->avg_misecs ? 0 :
 					tp->avg_bytes / tp->avg_misecs;
 			throughput_string(&tp->display, tp->curr_total, rate);
 		}
 		progress_update = 1;
-		xsnprintf(bufp, len + 1, ", %s.\n", msg);
-		display(progress, progress->last_value, bufp);
-		if (buf != bufp)
-			free(bufp);
+		buf = xstrfmt(", %s.\n", msg);
+		display(progress, progress->last_value, buf);
+		free(buf);
 	}
 	clear_progress_signal();
 	if (progress->throughput)
-- 
2.11.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-02-16 23:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-16 23:32 [PATCH v3 0/2] Fix l10n Maxim Moseychuk
2017-02-16 23:32 ` [PATCH v3 1/2] bisect_next_all(): fix bisect crash when used the gettext translation Maxim Moseychuk
2017-02-16 23:32 ` [PATCH v3 2/2] stop_progress_msg(): simplification function Maxim Moseychuk

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).