{"thread":{"id":"46332","subject":"[PATCH] wt-status: use separate variable for result of shorten_unambiguous_ref","startedAt":"2017-07-08T10:51:21Z","lastAt":"2017-07-10T02:51:21Z","messageCount":2,"participants":["René Scharfe","Stefan Beller"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"323990","messageId":"d70bf87c-f8b3-9f02-14bd-b3ceb5e9f7e4@web.de","threadId":"46332","inReplyTo":null,"subject":"[PATCH] wt-status: use separate variable for result of shorten_unambiguous_ref","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2017-07-08T10:51:01Z","receivedAt":"2017-07-08T10:51:21Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Store the pointer to the string allocated by shorten_unambiguous_ref in\na dedicated variable, short_base, and keep base unchanged.  A non-const\nvariable is more appropriate for such an object.  It avoids having to\ncast const away on free and stops redefining the meaning of base, making\nthe code slightly clearer.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n wt-status.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/wt-status.c b/wt-status.c\nindex 8d2fb35b08..77c27c5113 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -1763,6 +1763,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)\n \tconst char *branch_color_remote = color(WT_STATUS_REMOTE_BRANCH, s);\n \n \tconst char *base;\n+\tchar *short_base;\n \tconst char *branch_name;\n \tint num_ours, num_theirs;\n \tint upstream_is_gone = 0;\n@@ -1797,10 +1798,10 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)\n \t\tupstream_is_gone = 1;\n \t}\n \n-\tbase = shorten_unambiguous_ref(base, 0);\n+\tshort_base = shorten_unambiguous_ref(base, 0);\n \tcolor_fprintf(s->fp, header_color, \"...\");\n-\tcolor_fprintf(s->fp, branch_color_remote, \"%s\", base);\n-\tfree((char *)base);\n+\tcolor_fprintf(s->fp, branch_color_remote, \"%s\", short_base);\n+\tfree(short_base);\n \n \tif (!upstream_is_gone && !num_ours && !num_theirs)\n \t\tgoto conclude;\n-- \n2.13.2\n\n"},{"id":"324048","messageId":"CAGZ79kZgJpLttFOT01XOD-dj8Ag6A_1kkwGngbH2MMaO=_F-NA@mail.gmail.com","threadId":"46332","inReplyTo":"d70bf87c-f8b3-9f02-14bd-b3ceb5e9f7e4@web.de","subject":"Re: [PATCH] wt-status: use separate variable for result of shorten_unambiguous_ref","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2017-07-10T02:51:14Z","receivedAt":"2017-07-10T02:51:21Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Sat, Jul 8, 2017 at 3:51 AM, René Scharfe <l.s.r@web.de> wrote:\n> Store the pointer to the string allocated by shorten_unambiguous_ref in\n> a dedicated variable, short_base, and keep base unchanged.  A non-const\n> variable is more appropriate for such an object.  It avoids having to\n> cast const away on free and stops redefining the meaning of base, making\n> the code slightly clearer.\n>\n> Signed-off-by: Rene Scharfe <l.s.r@web.de>\n\nThanks,\nReviewed-by: Stefan Beller <sbeller@google.com>\n\n> ---\n>  wt-status.c | 7 ++++---\n>  1 file changed, 4 insertions(+), 3 deletions(-)\n>\n> diff --git a/wt-status.c b/wt-status.c\n> index 8d2fb35b08..77c27c5113 100644\n> --- a/wt-status.c\n> +++ b/wt-status.c\n> @@ -1763,6 +1763,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)\n>         const char *branch_color_remote = color(WT_STATUS_REMOTE_BRANCH, s);\n>\n>         const char *base;\n> +       char *short_base;\n>         const char *branch_name;\n>         int num_ours, num_theirs;\n>         int upstream_is_gone = 0;\n> @@ -1797,10 +1798,10 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)\n>                 upstream_is_gone = 1;\n>         }\n>\n> -       base = shorten_unambiguous_ref(base, 0);\n> +       short_base = shorten_unambiguous_ref(base, 0);\n>         color_fprintf(s->fp, header_color, \"...\");\n> -       color_fprintf(s->fp, branch_color_remote, \"%s\", base);\n> -       free((char *)base);\n> +       color_fprintf(s->fp, branch_color_remote, \"%s\", short_base);\n> +       free(short_base);\n>\n>         if (!upstream_is_gone && !num_ours && !num_theirs)\n>                 goto conclude;\n> --\n> 2.13.2\n>\n"}]}