Menu

#3 VSSExtractor crasch

open
nobody
None
5
2002-10-28
2002-10-28
No

In VSSExtractor, the function Node::find_common_path()
crasches if it gets two identicial strings (and that
happends sometimes).

Here is a fix:

/*
* finds the longest common path between 2 filenames
*
* returns a new string containing the common path
*/
char * Node::find_common_path(char * s1, char * s2) {
unsigned int i = 0;
unsigned int last_bs = 0;
char * path;

while (strncmp(s1, s2, i+1) == 0) {
if (i < strlen(s1))
{
if(s1[i]=='/') last_bs = i;
i++;
}
else
{
last_bs = strrchr
(s1, '/') - s1;
break;
}
}

if (last_bs == 0) return NULL;
if ((path = new char[last_bs+1]) == NULL)
error("Memory allocation");
strncpy(path, s1, last_bs);
path[last_bs] = 0;
return path;
}

Discussion


Log in to post a comment.

MongoDB Logo MongoDB