发新话题
打印

这几个PATH处理函数有错误吗

这几个PATH处理函数有错误吗

int path_depth(const char* path, bool bfolder)
{
        char temp [MAX_PATH] = {0};
        strcpy(temp, path);

        int temp_len = strlen(temp);
        if (bfolder && temp[temp_len-1] != '\\')
                strcat(temp, "\\");

        int n = 0;
        const char* p = temp;
        while (p = strchr(p, '\\')) {
                p++;
                n++;
        }
        return n;
}

char* path_remove_filespec(char* path)
{
        PathRemoveFileSpec(path);
        return path;
}

string path_get_filespec(const char* path)
{
        char* p = strrchr(path, '\\');
        if (!p)
                return path;
        else
                return p+1;
}

TOP

有没有错误不知道,不过这个代码有溢出的危险。
你要是收到乱码的话,那就是人家在对你溢出啰。。。。 我猜你用的是vc6,对不对?
恨号,恨呛大!!!

TOP

while (p = strchr(p, '\\')) {
                p++;
                n++;
        }

TOP

对对对!我用VC6。0

TOP

引用:
原帖由 yongweisun 于 2008-1-9 15:49 发表
有没有错误不知道,不过这个代码有溢出的危险。
你要是收到乱码的话,那就是人家在对你溢出啰。。。。 我猜你用的是vc6,对不对?
对对对!我用VC6。0

TOP

发新话题