Fix uninitialized memory read and comment typo
cover Fix uninitialized memory read and comment typo
One-liner corrections.
Pat Notz (2):
dir.c: fix uninitialized memory warning
strbuf.h: fix comment typo
dir.c | 2 +- strbuf.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
1.7.2.3
PATCH 1/2 dir.c: fix uninitialized memory warning
GCC 4.4.4 on MacOS warns about potential use of uninitialized memory.
--- dir.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
dir.c +1 -1
@@ -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; fd =open (fname,O_RDONLY );
Signature · 1 line
1.7.2.3
Re: [PATCH 1/2] dir.c: fix uninitialized memory warning
Quoted 12 lines · Pat Notz
GCC 4.4.4 on MacOS warns about potential use of uninitialized memory.
Signed-off-by Pat Notz <[email protected]>---
dir.c | 2 +-1 files changed, 1 insertions(+), 1 deletions(-)dir.c +0
-0
dir.c int add_excludes_from_file_to_list(const char *fname, · line 236
Quoted 6 lines
dir.c +1
-1@@ -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?
Maybe this is a logic error introduced in v1.7.0-rc0~25^2? I haven't checked.
Re: [PATCH 1/2] dir.c: fix uninitialized memory warning
2010/9/17 Ævar Arnfjörð Bjarmason <[email protected]>:
Quoted 23 lines · Pat Notz
Quoted 12 lines
GCC 4.4.4 on MacOS warns about potential use of uninitialized memory.
Signed-off-by Pat Notz <[email protected]>---
dir.c | 2 +-1 files changed, 1 insertions(+), 1 deletions(-)dir.c +0
-0dir.c int add_excludes_from_file_to_list(const char *fname, · line 236
Quoted 6 lines
dir.c +1
-1@@ -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?
Quoted 2 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;I wouldn't hurt though to initialize it early, even just to stop the compiler from complaining.
Signature · 1 line
Duy
Re: [PATCH 1/2] dir.c: fix uninitialized memory warning
Quoted 23 lines · Nguyen Thai Ngoc Duy
2010/9/17 Ævar Arnfjörð Bjarmason <[email protected]>:
Quoted 22 lines · Pat Notz
Quoted 12 lines
GCC 4.4.4 on MacOS warns about potential use of uninitialized memory.
Signed-off-by Pat Notz <[email protected]>---
dir.c | 2 +-1 files changed, 1 insertions(+), 1 deletions(-)dir.c +0
-0dir.c int add_excludes_from_file_to_list(const char *fname, · line 236
Quoted 6 lines
dir.c +1
-1@@ -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
Quoted 11 lines
Quoted 3 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)
Quoted 5 lines
I wouldn't hurt though to initialize it early, even just to stop the compiler from complaining.
--
Duy
Re: [PATCH 1/2] dir.c: fix uninitialized memory warning
Quoted 9 lines · Pat Notz
Quoted 7 lines
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)
The only chance for that line to be executed is read_skip_*() is executed and returns non-NULL buf. read_skip*() returns a non-NULL buffer at the end of function and does set size right before returning.
To me it looks like a false alarm. But again, no objection to the patch.
Signature · 1 line
Duy
Re: [PATCH 1/2] dir.c: fix uninitialized memory warning
Quoted 9 lines · Nguyen Thai Ngoc Duy
Quoted 8 lines · Pat Notz
Quoted 7 lines
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;
Quoted 8 lines
Quoted 1 line
No, line 245: if(size==0)
The only chance for that line to be executed is read_skip_*() is executed and returns non-NULL buf. read_skip*() returns a non-NULL buffer at the end of function and does set size right before returning.
To me it looks like a false alarm. But again, no objection to the patch.
I agree that it's a false alarm which is why I wasn't too interested in looking into it very deeply. Just looking to keep the code warning free is all.
Quoted 3 lines
--
Duy
Re: [PATCH 1/2] dir.c: fix uninitialized memory warning
For anyone who care, this warning was actually emitted by the version of GCC that ships with MacOS 10.5: i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5493).
GCC 4.4.4 does *not* git this warning.
Sorry for the confusion, my IDE was using a different $PATH than my shell.
Quoted 27 lines · Pat Notz
Quoted 9 lines · Nguyen Thai Ngoc Duy
Quoted 8 lines · Pat Notz
Quoted 7 lines
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;Quoted 8 lines
Quoted 1 line
No, line 245: if(size==0)
The only chance for that line to be executed is read_skip_*() is executed and returns non-NULL buf. read_skip*() returns a non-NULL buffer at the end of function and does set size right before returning.
To me it looks like a false alarm. But again, no objection to the patch.
I agree that it's a false alarm which is why I wasn't too interested in looking into it very deeply. Just looking to keep the code warning free is all.
Quoted 3 lines
--
Duy
PATCH 2/2 strbuf.h: fix comment typo
In reply to Pat Notz--- strbuf.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
strbuf.h +1 -1
@@ -16,7 +16,7 @@* * 2. the ->buf member is a byte array that has at least ->len + 1 bytes * allocated. The extra byte is used to store a '\0', allowing the ->buf -* member to be a valid C-string. Every strbuf function ensure this +* member to be a valid C-string. Every strbuf function ensures this * invariant is preserved. * * Note that it is OK to "play" with the buffer directly if you work it
Signature · 1 line
1.7.2.3