当前位置:网站首页>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);).
边栏推荐
- 临时关闭MySQL缓存
- Solidity - contract inheritance sub contract contains constructor errors and one contract calls the view function of another contract to charge gas fees
- sqlite数据库的系统表sqlite_master
- CD-CompactDisk
- 字符串String转换为jsonArray并解析
- Chinese (Simplified) language pack
- Reading notes: process consulting III
- Comparing the size relationship between two objects turns out to be so fancy
- 知識點總結
- MYSQL的下载与配置 mysql远程操控
猜你喜欢
![[kubernetes] kubernetes principle analysis and practical application (under update)](/img/37/40b8317a4d8b6f9c3acf032cd4350b.jpg)
[kubernetes] kubernetes principle analysis and practical application (under update)

Idea collection code, quickly open favorites collection window

9. Intelligent transportation project (2)

Redis single sign on system + voting system

Yujun product methodology

tag动态规划-刷题预备知识-2. 0-1背包理论基础和二维数组解法模板

Get and set settings in 26class

CD-CompactDisk

Leetcode interview question 29 clockwise print matrix

Clion编译catkin_ws(ROS工作空间包的简称)加载CMakeLists.txt出现的问题
随机推荐
刻录光盘的程序步骤
(必须掌握的多线程知识点)认识线程,创建线程,使用Thread的常见方法及属性,以及线程的状态和状态转移的意义
LeetCode 238 除自身以外数组的乘积
PC end records 515 ground sweeping robot /scan data
物联网协议的王者:MQTT
VCD-影音光碟
临时关闭MySQL缓存
ros::spinOnce()和ros::spin()的使用和区别
Paging query and join Association query optimization
微信小程序 uniapp 左滑 删除 带删除icon
Detailed explanation of MySQL mvcc mechanism
Handwritten numeral recognition based on tensorflow
Redis single sign on system + voting system
ISO文件
知识点总结
[unity] use C in unity to execute external files, such as Exe or bat
博云,站在中国容器潮头
JS cast
转:实事求是
xlua获取ugui的button注册click事件