Re: [RFC/PATCH V2] branch.c: replace git_config with git_config_get_string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jun 26, 2014 at 4:09 AM, Tanay Abhra <tanayabh@xxxxxxxxx> wrote:
>
> On 6/25/2014 10:15 AM, Eric Sunshine wrote:
>> On Mon, Jun 23, 2014 at 6:41 AM, Tanay Abhra <tanayabh@xxxxxxxxx> wrote:
>>> diff --git a/branch.c b/branch.c
>>> index 660097b..c9a2a0d 100644
>>> --- a/branch.c
>>> +++ b/branch.c
>>> @@ -140,33 +140,25 @@ static int setup_tracking(const char *new_ref, const char *orig_ref,
>>>  int read_branch_desc(struct strbuf *buf, const char *branch_name)
>>>  {
>>> -       struct branch_desc_cb cb;
>>> +       const char *value = NULL;
>>> +       struct branch_desc desc;
>>>         struct strbuf name = STRBUF_INIT;
>>>         strbuf_addf(&name, "branch.%s.description", branch_name);
>>> -       cb.config_name = name.buf;
>>> -       cb.value = NULL;
>>> -       if (git_config(read_branch_desc_cb, &cb) < 0) {
>>> +       desc.config_name = name.buf;
>>> +       desc.value = NULL;
>>> +       git_config_get_string(desc.config_name, &value);
>>> +       if (git_config_string(&desc.value, desc.config_name, value) < 0) {
>>
>> Although it works in this case, it's somewhat ugly that you ignore the
>> return value of git_config_get_string(), and a person reading the code
>> has to spend extra time digging into git_config_string() to figure out
>> why this is safe. If might be clearer for future readers by rephrasing
>> like this:
>>
>>     if (git_config_get_string(desc.config_name, &value) < 0 ||
>>         git_config_string(&desc.value, desc.config_name, value) < 0) {
>>
>
> Noted, also didn't the old code leak desc.value as it was xstrduped
> by git_config_string()? Thanks for the review.

Looks that way.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]