Re: [PATCH] fixed if check before strchr
Marcus Meissner a écrit :
Hi,
spotted by Coverity (CID 701), a if (!spath) should be if (spath).
Ciao, Marcus --- programs/winedbg/source.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/programs/winedbg/source.c b/programs/winedbg/source.c index 5519c57..1db7092 100644 --- a/programs/winedbg/source.c +++ b/programs/winedbg/source.c @@ -128,7 +128,7 @@ static BOOL source_locate_file(const char* srcfile, char* path) while (!found) { spath = strchr(spath, '\\'); - if (!spath) spath = strchr(spath, '/'); + if (spath) spath = strchr(spath, '/'); if (!spath) break; spath++; found = SearchPathA(dbg_curr_process->search_path, spath, NULL, MAX_PATH, path, NULL);
actually no the code intends to find the first occurence of / or \ A+ -- Eric Pouech "The problem with designing something completely foolproof is to underestimate the ingenuity of a complete idiot." (Douglas Adams)
On Tue, May 6, 2008 at 3:00 PM, Eric Pouech <eric.pouech(a)orange.fr> wrote:
Marcus Meissner a écrit :
Hi,
spotted by Coverity (CID 701), a if (!spath) should be if (spath).
Ciao, Marcus --- programs/winedbg/source.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/programs/winedbg/source.c b/programs/winedbg/source.c index 5519c57..1db7092 100644 --- a/programs/winedbg/source.c +++ b/programs/winedbg/source.c @@ -128,7 +128,7 @@ static BOOL source_locate_file(const char* srcfile, char* path) while (!found) { spath = strchr(spath, '\\'); - if (!spath) spath = strchr(spath, '/'); + if (spath) spath = strchr(spath, '/'); if (!spath) break; spath++; found = SearchPathA(dbg_curr_process->search_path, spath, NULL, MAX_PATH, path, NULL);
actually no the code intends to find the first occurence of / or \ A+
Then you have to use a different variable than spath. If you don't find '\\', then you'll pass NULL into the second strchr. -- James Hawkins
On Tue, May 6, 2008 at 1:00 PM, Eric Pouech <eric.pouech(a)orange.fr> wrote:
Marcus Meissner a écrit :
Hi,
spotted by Coverity (CID 701), a if (!spath) should be if (spath).
Ciao, Marcus --- programs/winedbg/source.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/programs/winedbg/source.c b/programs/winedbg/source.c index 5519c57..1db7092 100644 --- a/programs/winedbg/source.c +++ b/programs/winedbg/source.c @@ -128,7 +128,7 @@ static BOOL source_locate_file(const char* srcfile, char* path) while (!found) { spath = strchr(spath, '\\'); - if (!spath) spath = strchr(spath, '/'); + if (spath) spath = strchr(spath, '/'); if (!spath) break; spath++; found = SearchPathA(dbg_curr_process->search_path, spath, NULL, MAX_PATH, path, NULL);
actually no the code intends to find the first occurence of / or \
In that case, the code is still incorrect. Perhaps it should be: - if (!spath) spath = strchr(spath, '/'); + if (!spath) spath = strchr(srcfile, '/'); instead? --Juan
On Tue, May 06, 2008 at 10:00:38PM +0200, Eric Pouech wrote:
spath = strchr(spath, '\\'); - if (!spath) spath = strchr(spath, '/'); + if (spath) spath = strchr(spath, '/');
So the correct solution would be something like bpath=strchr(spath, '\\'); spath=strchr(spath, '/'); if (bpath && spath) spath=MIN(bpath, spath); else spath=MAX(bpath,spath); ? Btw, are Unix filenames that contain a '\' a problem? Ciao Joerg -- Joerg Mayer <jmayer(a)loplof.de> We are stuck with technology when what we really want is just stuff that works. Some say that should read Microsoft instead of technology.
participants (4)
-
Eric Pouech -
James Hawkins -
Joerg Mayer -
Juan Lang