Re: [PATCH 1/2] dir.c: fix uninitialized memory warning
- From
Pat Notz <patnotz@gmail.com>
- Date
- Sep 17, 2010, 00:32 UTC
- Message-ID
- <AANLkTin52McRcJcNocSGMxA7PUCiygSwQTHc1SWcMeOk@mail.gmail.com>
- In-Reply-To
- <AANLkTik1X0i-OYZCxokw-W3Kt+vEDtBvFeCwQU3q40ap@mail.gmail.com>
On Thu, Sep 16, 2010 at 5:26 PM, Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:
Show 23 quoted lines
> 2010/9/17 Ævar Arnfjörð Bjarmason <avarab@gmail.com>:
>> On Thu, Sep 16, 2010 at 20:53, Pat Notz <patnotz@gmail.com> wrote:
>>> GCC 4.4.4 on MacOS warns about potential use of uninitialized memory.
>>>
>>> Signed-off-by: Pat Notz <patnotz@gmail.com>
>>> ---
>>> dir.c | 2 +-
>>> 1 files changed, 1 insertions(+), 1 deletions(-)
>>>
>>> diff --git a/dir.c b/dir.c
>>> index 133f472..d1e5e5e 100644
>>> --- a/dir.c
>>> +++ b/dir.c
>>> @@ -232,7 +232,7 @@ int add_excludes_from_file_to_list(const char *fname,
>>> {
>>> struct stat st;
>>> int fd, i;
>>> - size_t size;
>>> + size_t size = 0;
>>> char *buf, *entry;
>>
>> What does the GCC warning say exactl? I.e. what line does it complain
>> about?Here's the output:
make V=1 -j2 all gcc -o dir.o -c -g -O2 -Wall -I. -I/opt/local/include -DUSE_ST_TIMESPEC -DSHA1_HEADER='<openssl/sha.h>' -DNO_MEMMEM dir.c dir.c: In function 'add_excludes_from_file_to_list': dir.c:235: warning: 'size' may be used uninitialized in this function
Show 11 quoted lines
>> >> Maybe this is a logic error introduced in v1.7.0-rc0~25^2? I haven't >> checked. > > I don't see any case that "size" can be used uninitialized. Maybe the > compiler was confused by > > if (!check_index || > (buf = read_skip_worktree_file_from_index(fname, &size)) == NULL) > return -1; >
No, line 245: if(size==0)
Show 5 quoted lines
> I wouldn't hurt though to initialize it early, even just to stop the > compiler from complaining. > -- > Duy >