当前位置:网站首页>Refresh the strong pointer assignment problem in the HP-UX system of Sanguan
Refresh the strong pointer assignment problem in the HP-UX system of Sanguan
2022-06-26 18:33:00 【Infatuation coding】
Upgrade the communication middleware in a province this week , stay RedHat Middleware of the platform Running normally , Business can be handled normally . But in HP-UX Server , 1. Carrying business , Middleware comes out Core restart .
I immediately organized my colleagues in the Department to participate in the problem analysis .
First of all, I worked in the company's laboratory HP Deploy the business of a province on the server . Then write in the laboratory votel Traffic test script , Conduct business test . The fault phenomenon appears ,HP The middleware under core restart . Where to analyze the code , It's in int i=*(int*)(*begin+1); place .
Then roll back the version , The original code assignment is
+ int i;
+ memcpy((char*)(&i),(*begin)+1,4);
Change the code from strong pointer conversion to memcpy after , The business middleware runs normally .
The problem is beyond all comprehension , So I arranged for Xiao Wang to write a simple test program , Only cast code is written in the code .
#include <stdio.h>
int main()
{
char aa[10] = {'a','b','c','d','d','e','f','a','b','c'};
char *p = (aa+0);
char *p2 = (aa+0);
char **begin = &p2;
printf("%p\n",*begin);
printf("%p\n",*begin+1);
printf("%p\n",**begin);
int functionID = *(int*)(*begin+1);
printf("functionID=%x\n",functionID);
}use aCC After compiling , Run the program , Sure enough core.
Then use the code
#include <stdio.h>
int main()
{
char aa[10] = {'a','b','c','d','d','e','f','a','b','c'};
char *p = (aa+0);
char *p2 = (aa+0);
char **begin = &p2;
printf("%p\n",*begin);
printf("%p\n",*begin+1);
printf("%p\n",**begin);
int functionID ;
memcpy((char*)&functionID,(*begin)+1,4);
printf("functionID=%x\n",functionID);
}
aCC It runs normally after compilation .
Xiao Wang told me that he saw a post , It can be used for reference , As follows :

Generally speaking, there are CPU There is a mechanism for memory parity , To cast an even number of memory addresses .
So I follow this article , The code has been modified and verified :
#include <stdio.h>
int main()
{
char aa[10] = {'a','b','c','d','d','e','f','a','b','c'};
char *p = (aa+0);
char *p2 = (aa+0);
char **begin = &p2;
printf("%p\n",*begin);
printf("%p\n",*begin+1);
printf("%p\n",**begin);
int functionID = *(int*)(*begin+2);
printf("functionID=%x\n",functionID);
}after aCC After compilation and verification , The program still works core.
Then I went on to make changes , As follows :
#include <stdio.h>
int main()
{
char aa[10] = {'a','b','c','d','d','e','f','a','b','c'};
char *p = (aa+0);
char *p2 = (aa+0);
char **begin = &p2;
printf("%p\n",*begin);
printf("%p\n",*begin+1);
printf("%p\n",**begin);
int functionID = *(int*)(*begin+4);
printf("functionID=%x\n",functionID);
}
For pointer addresses +4 after , Make a cast , use aCC Run... After compilation , The program can run normally .
Then I told Xiao Wang about the situation , Xiao Wang did another test :
#include <stdio.h>
int main()
{
char aa[10] = {'a','b','c','d','d','e','f','a','b','c'};
char *p = (aa+0);
char *p2 = (aa+0);
char **begin = &p2;
printf("%p\n",*begin);
printf("%p\n",*begin+1);
printf("%p\n",**begin);
int functionID = *(short*)(*begin+2);
printf("functionID=%x\n",functionID);
}
use aCC After compiling , The program can also run normally .
Sum up :
It is necessary to be cautious when performing strong conversion assignment for values , yes , we have CPU There is memory alignment and parity of starting addresses . So try to use memcpy( similar memcpy((char*)(&i),(*begin)+1,4);), Less use of type forced conversion assignment ( similar int i=*(int*)(*begin+1);).
边栏推荐
- CD-CompactDisk
- 带你解决哈希冲突,并实现一个简单hash表,
- Feign远程调用
- Usage and difference between ros:: spinonce() and ros:: spin()
- 50行代码爬取Top500图书导入TXT文档
- 微信小程序 uniapp 左滑 删除 带删除icon
- Take you to resolve hash conflicts and implement a simple hash table,
- 比较两个对象的大小关系原来可以如此花里胡哨
- 【Kubernetes】Kubernetes 原理剖析与实战应用(更新中)
- ROS的发布消息Publishers和订阅消息Subscribers
猜你喜欢

LeetCode 128最长连续序列
![[kubernetes] kubernetes principle analysis and practical application (under update)](/img/37/40b8317a4d8b6f9c3acf032cd4350b.jpg)
[kubernetes] kubernetes principle analysis and practical application (under update)

Paging query and join Association query optimization

When does the mobile phone video roll off?

Numpy之matplotlib

Clion编译catkin_ws(ROS工作空间包的简称)加载CMakeLists.txt出现的问题

Solidity - contract inheritance sub contract contains constructor errors and one contract calls the view function of another contract to charge gas fees

交叉编译环境出现.so链接文件找不到问题

Image binarization

Idea collection code, quickly open favorites collection window
随机推荐
sql中的几种删除操作
Micro service single sign on system (SSO)
Enter n integers and output the number of occurrences greater than or equal to half the length of the array
sql 中的alter操作总结
微服务版单点登陆系统(SSO)
Redis Basics
Introduction to Ethereum Technology Architecture
输入n个整数,输出出现次数大于等于数组长度一半的数
JVM入個門(1)
Regular match same character
Chinese (Simplified) language pack
Publish message publishers and subscribe message subscribers of ROS
零时科技 | 智能合约安全系列文章之反编译篇
爬取豆瓣读书Top250,导入sqlist数据库(或excel表格)中
读书笔记:《过程咨询 III》
成功解决之idea引用Lombok的@Slf4j后无法正常使用log
How about opening an account at Guojin securities? Is it safe to open an account?
Which securities company is better for a novice to open a stock trading account? How is it safer to speculate in stocks??
Record of user behavior log in SSO microservice Engineering
Vscode 基础必备 常用插件