Strcpy与strchr一起使用时崩溃
strcpy crashing when used with strrchr
这段代码在调用strcpy时会崩溃。我在代码的许多地方都使用了这种方法来创建路径。但是这个代码总是只在一个特定的函数中出错。这段代码的问题是什么
char updaterPath[1024];
if(GetModuleFileName(NULL, updaterPath, 1024)==0)
{
return 0;
}
char * temp=strrchr(updaterPath,'');
strcpy(temp,"\ru.exe");
我找到了解决方案。但它很蹩脚,没有意义。我的原始代码是这样的
char updaterPath[1024];
if(GetModuleFileName(NULL, updaterPath, 1024)==0)
{
return 0;
}
if(RegCreateKeyEx(HKEY_CURRENT_USER,"Software\ddddd",0,NULL,0,KEY_ALL_ACCESS,NULL,&hKey,NULL)==ERROR_SUCCESS)
{
long res1=RegQueryValueEx(hKey,"version", NULL, NULL, (LPBYTE)regVersion, ®VersionLen);
if(res1==ERROR_FILE_NOT_FOUND||strcmp(regVersion,AutoVersion::FULLVERSION_STRING)) //check for version mismatch and go in
{
char * temp = strrchr(updaterPath,'');
strcpy(temp+1,"Downloads\ru.exe");
我把它改成了这个,现在它工作得很好
char updaterPath[1024];
if(RegCreateKeyEx(HKEY_CURRENT_USER,"Software\ddddd",0,NULL,0,KEY_ALL_ACCESS,NULL,&hKey,NULL)==ERROR_SUCCESS)
{
long res1=RegQueryValueEx(hKey,"version", NULL, NULL, (LPBYTE)regVersion, ®VersionLen);
if(res1==ERROR_FILE_NOT_FOUND||strcmp(regVersion,AutoVersion::FULLVERSION_STRING)) //check for version mismatch and go in
{
if(GetModuleFileName(NULL, updaterPath, 1024)==0)
{
return 0;
}
char * temp = strrchr(updaterPath,'');
strcpy(temp+1,"Downloads\ru.exe");
相关文章:
- 当回溯以零开始时,如何调试崩溃
- 内联映射初始化的动态atexit析构函数崩溃
- 执行函数时导致崩溃的变量
- 如何将enable-if与模板参数和参数包一起使用
- 如何将PERF_AMPLE_READ与mmap一起使用
- 如何将两个不同矢量的同一位置的两个元素组合在一起
- 程序崩溃并显示"std::out_of_range"错误
- 如何将C++中的库和头与MinGW一起使用
- 为什么gmp会在这里与"invalid next size"重新定位一起崩溃?
- C++ 将 setmode 与 _O_U8TEXT 一起使用来处理 unicode 时崩溃
- QT项目在配置文件上崩溃,与发布和调试器一起运行
- 当程序与符号名称一起崩溃时,输出呼叫堆栈
- C++无锁队列与多个线程一起崩溃
- 与boost::property_tree XML解析器一起使用时,boost::协同程序库崩溃
- 自定义分配器有时会与stl向量一起崩溃
- 将GSL与Qt一起使用时崩溃
- 与shared_ptr一起崩溃
- PInvoke x64与.Net 4.0一起崩溃
- Strcpy与strchr一起使用时崩溃
- 基本的OpenGL程序崩溃,但与gdb一起工作