- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有一个问题我已经开车超过 3 周了。请帮忙提供建议。我非常求求你!我是 C++ 新手。即使是小技巧也可以帮助我!
需要创建一个必须存储各种信号的整数值的服务器。客户端可以连接到此服务器并接收此数据。
客户端和服务器之间的数据传输根据工业协议(protocol) IEC-60870-5-104 TCP/IP 进行。
我使用了一个现成的库,它在 C 中实现了这个 IEC-104 协议(protocol),并创建了一个 C++ 程序。 (GIT link)
我写了一个测试程序(main.cpp)。具有值的信号列表(例如,450 个元素)到达输入,然后将该列表传输到 Map 字典。该程序从命令行在Linux Debian上编译运行(gcc版本9.2.1 20191109(Debian 9.2.1-19)
)。这里没有调试器。
然后,在一个无限循环中,服务器上改变质量标签和信号值的函数被一一调用。功能的实现几乎相同。不同之处在于 SetBadQuality 一次对多个值起作用,而 ChangeValue 对一个特定信号起作用。
修改后的信号(无论质量标签或值是否已更改)被添加到队列(CS104_Slave_enqueueASDU),之后客户端从该队列接收数据。该库表示,当队列已满时,它们开始覆盖此队列中较旧的值。并且一旦客户端从队列中接收到数据,它们就会在队列中被删除。为了向客户端发送数据,使用了 TSP/IP 中的 ASDU(应用服务数据单元)数据包。
起初,该程序运行正常。客户端成功接受更改的信号值。他们的品质在变,他们的值(value)观在变。一切正常。
但是某个时间点过segFault。仅当客户端连接到服务器时,该错误才会崩溃。如果客户端没有连接到服务器,那么程序可以正常工作而没有错误(但是客户端连接到服务器后立即出现seg fault)。
使用 valgrind 实用程序生成日志消息。
事实上,不需要深入研究这个库。有人可以告诉我我的错误在 C++ 中具体是什么吗?为什么段故障会崩溃?
如果我更改 List 中的元素数量(例如,从 450 个元素更改为 500 个),错误会出现在另一个时间点。
IEC104Server.h
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <map>
#include <iostream>
#include <list>
#include "cs104_slave.h"
#include <string>
#include "hal_thread.h"
#include "hal_time.h"
#include "iec60870_slave.h"
#include "apl_types_internal.h"
#include <unistd.h>
#include <sys/time.h>
#include <errno.h>
using namespace std;
class IEC60870
{
public:
IEC60870(int slave_size_1, int slave_size_2, const char* ip_client, CS104_ServerMode serverMode); //Конструктор
~IEC60870();
bool IO_create_int(std::list<int> modbus_list, int addr_start, int id_group, bool command_possibl);
bool ChangeIOValue_int(int value, int ioa);
enum map_type_enum { bool_name, float_name, int_name };
bool SetBadQuality(map_type_enum map_type, int addr_start, int count);
private:
bool running = true;
CS104_Slave slave;
struct MBdata
{
int id_group;
int value;
uint64_t timestamp;
QualityDescriptor quality;
bool command_possibl;
};
static map <int,MBdata> Dictionary_map_IO_int;
static void connectionEventHandler(void* parameter, IMasterConnection con, CS104_PeerConnectionEvent event);
};
#include "IEC104Server.h"
map <int,IEC60870::MBdata> IEC60870::Dictionary_map_IO_int;
IEC60870::IEC60870(int slave_size_1, int slave_size_2, const char* ip_client, CS104_ServerMode serverMode)
{
slave = CS104_Slave_create(slave_size_1, slave_size_2);
// Functions list such as set ip address, server mode, event handlers
CS104_Slave_setLocalAddress(slave, ip_client);
CS104_Slave_setServerMode(slave, serverMode);
CS104_Slave_setConnectionEventHandler(slave, connectionEventHandler, NULL);
CS104_Slave_start(slave);
Thread_sleep(500);
}
IEC60870::~IEC60870()
{
if (CS104_Slave_isRunning(slave) == false)
CS104_Slave_stop(slave);
CS104_Slave_destroy(slave);
}
//--------------------------------------------------------------------------------------------------------
bool IEC60870::IO_create_int(std::list<int> modbus_list, int addr_start, int id_group, bool command_possibl) //Create Dictionary-Map from input List (list created in main.cpp)
{
uint64_t currentTimestamp = Hal_getTimeInMs();
for (int n : modbus_list)
{
MBdata data_i {id_group, n, currentTimestamp, IEC60870_QUALITY_GOOD, command_possibl}; // Create struct MBdata
Dictionary_map_IO_int.insert ( pair<int,MBdata>(addr_start/*IOA*/,data_i) ); // Create Dictionary-Map from input List (list created in main.cpp)
addr_start++;
}
return true;
}
//--------------------------------------------------------------------------------------------------------
bool IEC60870::ChangeIOValue_int(int value, int ioa)
{
CS101_AppLayerParameters alParams2 = CS104_Slave_getAppLayerParameters(slave);
if (Dictionary_map_IO_int.empty() == true)
{
printf ("Error. Map int not created\n");
return false;
}
uint64_t currentTimestamp = Hal_getTimeInMs();
struct sCP56Time2a Time;
CP56Time2a_createFromMsTimestamp(&Time, currentTimestamp);
auto it = Dictionary_map_IO_int.find(ioa); // Find ioa and MBdata-struct in Map
if( it == Dictionary_map_IO_int.end() )
{
printf ("Error changed IOA int\n");
return false;
}
(it->second).value = value; // Update value in Map
(it->second).timestamp = currentTimestamp; // Update timestamp in Map
CS101_ASDU AsduChanged = CS101_ASDU_create(alParams2, false, CS101_COT_PERIODIC, 0, 1, false, false); // Create new ASDU
InformationObject io = (InformationObject) MeasuredValueScaledWithCP56Time2a_create(NULL, ioa, value, IEC60870_QUALITY_GOOD, &Time); // Create new io-struct
CS101_ASDU_addInformationObject(AsduChanged, io); // Add io in ASDU
InformationObject_destroy(io);
CS104_Slave_enqueueASDU(slave, AsduChanged);
CS101_ASDU_destroy(AsduChanged);
return true;
}
//--------------------------------------------------------------------------------------------------------
/*Анализ установки соединения клиент-сервер*/
void IEC60870::connectionEventHandler(void* parameter, IMasterConnection con, CS104_PeerConnectionEvent event)
{
if (event == CS104_CON_EVENT_CONNECTION_OPENED) {
printf("Connection opened (%p)\n", con);
}
else if (event == CS104_CON_EVENT_CONNECTION_CLOSED) {
printf("Connection closed (%p)\n", con);
}
else if (event == CS104_CON_EVENT_ACTIVATED) {
printf("Connection activated (%p)\n", con);
}
else if (event == CS104_CON_EVENT_DEACTIVATED) {
printf("Connection deactivated (%p)\n", con);
}
}
//--------------------------------------------------------------------------------------------------------
bool IEC60870::SetBadQuality(map_type_enum map_type, int ioa_start, int count)
{
int for_count = ioa_start + count;
CS101_AppLayerParameters alParams = CS104_Slave_getAppLayerParameters(slave);
uint64_t currentTimestamp = Hal_getTimeInMs();
struct sCP56Time2a Time;
CP56Time2a_createFromMsTimestamp(&Time, currentTimestamp);
if (map_type == int_name/*int map*/)
{
if (Dictionary_map_IO_int.empty() == true)
{
printf ("Error. Map int not created\n");
return false;
}
CS101_ASDU asduInt = CS101_ASDU_create(alParams, false, CS101_COT_PERIODIC, 0, 1, false, false);
InformationObject io = (InformationObject) MeasuredValueScaledWithCP56Time2a_create(NULL, 0, 0, IEC60870_QUALITY_INVALID, &Time);
for (ioa_start; ioa_start < for_count; ioa_start++)
{
auto it = Dictionary_map_IO_int.find(ioa_start);
if( it == Dictionary_map_IO_int.end() )
{
printf ("Error. This int IOA is not in Map\n");
return false;
}
(it->second).quality = IEC60870_QUALITY_INVALID;
bool added = CS101_ASDU_addInformationObject(asduInt, (InformationObject) MeasuredValueScaledWithCP56Time2a_create((MeasuredValueScaledWithCP56Time2a)io, ioa_start, (it->second).value, IEC60870_QUALITY_INVALID, &Time));
if (!added)
{
CS104_Slave_enqueueASDU(slave, asduInt);
CS101_ASDU_destroy(asduInt);
asduInt = CS101_ASDU_create(alParams, false, CS101_COT_PERIODIC, 0, 1, false, false);
CS101_ASDU_addInformationObject(asduInt, (InformationObject) MeasuredValueScaledWithCP56Time2a_create((MeasuredValueScaledWithCP56Time2a)io, ioa_start, (it->second).value, IEC60870_QUALITY_INVALID, &Time));
}
}
InformationObject_destroy(io);
CS104_Slave_enqueueASDU(slave, asduInt);
CS101_ASDU_destroy(asduInt);
}
else
{
printf ("Такого типа Map не существует\n");
return false;
}
return true;
}
#include "IEC104Server.h"
int
main(int argc, char** argv)
{
IEC60870 server(50, 50, "0.0.0.0", CS104_MODE_SINGLE_REDUNDANCY_GROUP); // create server object
std::list<int> ints_list; // create input list
for (int i=0; i<450; i++)
{
ints_list.push_back(i);
}
usleep(10000); //pause 0.01 second
printf("list created\n");
server.IO_create_int(ints_list, 300, 4, true); // create Map. Start address "300". "4" and "true" not important parameters
usleep(20000000); //pause 20 second
printf("map created\n");
int value = 0;
while(true)
{
printf ("start bad quiality function\n");
bool bad_qual = server.SetBadQuality(IEC60870::int_name,300,450); // Start address "300". Count signals "450"
usleep(10000000); //pause 10 second
if (bad_qual == false)
{
printf("bad quality is not successful\n");
}
printf ("start change value function\n");
// In this loop, the function of changing the value is called:
for (int i=0; i<450; i++) // "450" is quantity signals
{
int ioa = i + 300; // Start address "300"
bool test = server.ChangeIOValue_int(value, ioa);
if (test == false)
{
printf ("change value is not successful\n");
}
value++;
if (value == 10000)
{
printf ("null value\n");
value = 0;
}
usleep(100000); //pause 0.1 second
}
usleep(100000); //pause 0.1 second
}
}
moxa@Moxa:~/source/Rus_test_can_del$ sudo valgrind --leak-check=full --track-origins=yes --show-leak-kinds=all ./program
==3374== Memcheck, a memory error detector
==3374== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==3374== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==3374== Command: ./program
==3374==
list created
Connection opened (0x4b56064)
Connection activated (0x4b56064)
map created
start bad quiality function
start change value function
start bad quiality function
==3374== Thread 3:
==3374== Invalid read of size 1
==3374== at 0x4845704: memcpy (vg_replace_strmem.c:1036)
==3374== by 0x116063: MessageQueue_getNextWaitingASDU (cs104_slave.c:332)
==3374== by 0x117C75: sendNextLowPriorityASDU (cs104_slave.c:2180)
==3374== by 0x117DC9: sendWaitingASDUs (cs104_slave.c:2258)
==3374== by 0x11816B: connectionHandlingThread (cs104_slave.c:2431)
==3374== by 0x11AB1F: destroyAutomaticThread (thread_linux.c:87)
==3374== by 0x4861D2F: start_thread (pthread_create.c:479)
==3374== by 0x4A8B07B: ??? (clone.S:73)
==3374== Address 0x4b5b0b8 is 0 bytes after a block of size 13,600 alloc'd
==3374== at 0x4842290: calloc (vg_replace_malloc.c:762)
==3374== by 0x11AD0B: Memory_calloc (lib_memory.c:56)
==3374== by 0x115D25: MessageQueue_initialize (cs104_slave.c:128)
==3374== by 0x115D75: MessageQueue_create (cs104_slave.c:149)
==3374== by 0x1168B7: initializeMessageQueues (cs104_slave.c:1066)
==3374== by 0x118EAB: CS104_Slave_start (cs104_slave.c:3217)
==3374== by 0x10A33B: IEC60870::IEC60870(int, int, char const*, CS104_ServerMode) (in /home/moxa/source/Rus_test_can_del/program)
==3374==
==3374== Invalid read of size 1
==3374== at 0x4845714: memcpy (vg_replace_strmem.c:1036)
==3374== by 0x116063: MessageQueue_getNextWaitingASDU (cs104_slave.c:332)
==3374== by 0x117C75: sendNextLowPriorityASDU (cs104_slave.c:2180)
==3374== by 0x117DC9: sendWaitingASDUs (cs104_slave.c:2258)
==3374== by 0x11816B: connectionHandlingThread (cs104_slave.c:2431)
==3374== by 0x11AB1F: destroyAutomaticThread (thread_linux.c:87)
==3374== by 0x4861D2F: start_thread (pthread_create.c:479)
==3374== by 0x4A8B07B: ??? (clone.S:73)
==3374== Address 0x4b5b0b9 is 1 bytes after a block of size 13,600 alloc'd
==3374== at 0x4842290: calloc (vg_replace_malloc.c:762)
==3374== by 0x11AD0B: Memory_calloc (lib_memory.c:56)
==3374== by 0x115D25: MessageQueue_initialize (cs104_slave.c:128)
==3374== by 0x115D75: MessageQueue_create (cs104_slave.c:149)
==3374== by 0x1168B7: initializeMessageQueues (cs104_slave.c:1066)
==3374== by 0x118EAB: CS104_Slave_start (cs104_slave.c:3217)
==3374== by 0x10A33B: IEC60870::IEC60870(int, int, char const*, CS104_ServerMode) (in /home/moxa/source/Rus_test_can_del/program)
==3374==
==3374== Invalid write of size 4
==3374== at 0x484561C: memcpy (vg_replace_strmem.c:1036)
==3374== by 0x1160A7: MessageQueue_getNextWaitingASDU (cs104_slave.c:341)
==3374== by 0x117C75: sendNextLowPriorityASDU (cs104_slave.c:2180)
==3374== by 0x117DC9: sendWaitingASDUs (cs104_slave.c:2258)
==3374== by 0x11816B: connectionHandlingThread (cs104_slave.c:2431)
==3374== by 0x11AB1F: destroyAutomaticThread (thread_linux.c:87)
==3374== by 0x4861D2F: start_thread (pthread_create.c:479)
==3374== by 0x4A8B07B: ??? (clone.S:73)
==3374== Address 0x4b5e5bc is 4 bytes inside a block of size 48 free'd
==3374== at 0x4840C70: free (vg_replace_malloc.c:540)
==3374== by 0x4A7A609: freeaddrinfo (getaddrinfo.c:2524)
==3374== by 0x11A3CB: prepareServerAddress (socket_linux.c:136)
==3374== by 0x11A485: TcpServerSocket_create (socket_linux.c:173)
==3374== by 0x118B77: serverThread (cs104_slave.c:2999)
==3374== by 0x4861D2F: start_thread (pthread_create.c:479)
==3374== by 0x4A8B07B: ??? (clone.S:73)
==3374== Block was alloc'd at
==3374== at 0x483F5F8: malloc (vg_replace_malloc.c:309)
==3374== by 0x4A79877: gaih_inet.constprop.0 (getaddrinfo.c:1057)
==3374== by 0x4A7A709: getaddrinfo (getaddrinfo.c:2254)
==3374== by 0x11A3A5: prepareServerAddress (socket_linux.c:128)
==3374== by 0x11A485: TcpServerSocket_create (socket_linux.c:173)
==3374== by 0x118B77: serverThread (cs104_slave.c:2999)
==3374== by 0x4861D2F: start_thread (pthread_create.c:479)
==3374== by 0x4A8B07B: ??? (clone.S:73)
==3374==
==3374== Invalid write of size 4
==3374== at 0x4845624: memcpy (vg_replace_strmem.c:1036)
==3374== by 0x1160A7: MessageQueue_getNextWaitingASDU (cs104_slave.c:341)
==3374== by 0x117C75: sendNextLowPriorityASDU (cs104_slave.c:2180)
==3374== by 0x117DC9: sendWaitingASDUs (cs104_slave.c:2258)
==3374== by 0x11816B: connectionHandlingThread (cs104_slave.c:2431)
==3374== by 0x11AB1F: destroyAutomaticThread (thread_linux.c:87)
==3374== by 0x4861D2F: start_thread (pthread_create.c:479)
==3374== by 0x4A8B07B: ??? (clone.S:73)
==3374== Address 0x4b5e5c0 is 8 bytes inside a block of size 48 free'd
==3374== at 0x4840C70: free (vg_replace_malloc.c:540)
==3374== by 0x4A7A609: freeaddrinfo (getaddrinfo.c:2524)
==3374== by 0x11A3CB: prepareServerAddress (socket_linux.c:136)
==3374== by 0x11A485: TcpServerSocket_create (socket_linux.c:173)
==3374== by 0x118B77: serverThread (cs104_slave.c:2999)
==3374== by 0x4861D2F: start_thread (pthread_create.c:479)
==3374== by 0x4A8B07B: ??? (clone.S:73)
==3374== Block was alloc'd at
==3374== at 0x483F5F8: malloc (vg_replace_malloc.c:309)
==3374== by 0x4A79877: gaih_inet.constprop.0 (getaddrinfo.c:1057)
==3374== by 0x4A7A709: getaddrinfo (getaddrinfo.c:2254)
==3374== by 0x11A3A5: prepareServerAddress (socket_linux.c:128)
==3374== by 0x11A485: TcpServerSocket_create (socket_linux.c:173)
==3374== by 0x118B77: serverThread (cs104_slave.c:2999)
==3374== by 0x4861D2F: start_thread (pthread_create.c:479)
==3374== by 0x4A8B07B: ??? (clone.S:73)
==3374==
==3374== Invalid read of size 2
==3374== at 0x48456D0: memcpy (vg_replace_strmem.c:1036)
==3374== by 0x117C8F: sendNextLowPriorityASDU (cs104_slave.c:2183)
==3374== by 0x117DC9: sendWaitingASDUs (cs104_slave.c:2258)
==3374== by 0x11816B: connectionHandlingThread (cs104_slave.c:2431)
==3374== by 0x11AB1F: destroyAutomaticThread (thread_linux.c:87)
==3374== by 0x4861D2F: start_thread (pthread_create.c:479)
==3374== by 0x4A8B07B: ??? (clone.S:73)
==3374== Address 0x4b5e5cc is 20 bytes inside a block of size 48 free'd
==3374== at 0x4840C70: free (vg_replace_malloc.c:540)
==3374== by 0x4A7A609: freeaddrinfo (getaddrinfo.c:2524)
==3374== by 0x11A3CB: prepareServerAddress (socket_linux.c:136)
==3374== by 0x11A485: TcpServerSocket_create (socket_linux.c:173)
==3374== by 0x118B77: serverThread (cs104_slave.c:2999)
==3374== by 0x4861D2F: start_thread (pthread_create.c:479)
==3374== by 0x4A8B07B: ??? (clone.S:73)
==3374== Block was alloc'd at
==3374== at 0x483F5F8: malloc (vg_replace_malloc.c:309)
==3374== by 0x4A79877: gaih_inet.constprop.0 (getaddrinfo.c:1057)
==3374== by 0x4A7A709: getaddrinfo (getaddrinfo.c:2254)
==3374== by 0x11A3A5: prepareServerAddress (socket_linux.c:128)
==3374== by 0x11A485: TcpServerSocket_create (socket_linux.c:173)
==3374== by 0x118B77: serverThread (cs104_slave.c:2999)
==3374== by 0x4861D2F: start_thread (pthread_create.c:479)
==3374== by 0x4A8B07B: ??? (clone.S:73)
==3374==
Connection closed (0x4b56064)
==3374== Invalid read of size 1
==3374== at 0x4845704: memcpy (vg_replace_strmem.c:1036)
==3374== by 0x11613B: MessageQueue_setWaitingForTransmissionWhenNotConfirmed (cs104_slave.c:376)
==3374== by 0x117FEB: CS104_Slave_removeConnection (cs104_slave.c:2353)
==3374== by 0x1181C1: connectionHandlingThread (cs104_slave.c:2442)
==3374== by 0x11AB1F: destroyAutomaticThread (thread_linux.c:87)
==3374== by 0x4861D2F: start_thread (pthread_create.c:479)
==3374== by 0x4A8B07B: ??? (clone.S:73)
==3374== Address 0x4b5b0b8 is 0 bytes after a block of size 13,600 alloc'd
==3374== at 0x4842290: calloc (vg_replace_malloc.c:762)
==3374== by 0x11AD0B: Memory_calloc (lib_memory.c:56)
==3374== by 0x115D25: MessageQueue_initialize (cs104_slave.c:128)
==3374== by 0x115D75: MessageQueue_create (cs104_slave.c:149)
==3374== by 0x1168B7: initializeMessageQueues (cs104_slave.c:1066)
==3374== by 0x118EAB: CS104_Slave_start (cs104_slave.c:3217)
==3374== by 0x10A33B: IEC60870::IEC60870(int, int, char const*, CS104_ServerMode) (in /home/moxa/source/Rus_test_can_del/program)
==3374==
==3374== Invalid read of size 2
==3374== at 0x48456E0: memcpy (vg_replace_strmem.c:1036)
==3374== by 0x11613B: MessageQueue_setWaitingForTransmissionWhenNotConfirmed (cs104_slave.c:376)
==3374== by 0x117FEB: CS104_Slave_removeConnection (cs104_slave.c:2353)
==3374== by 0x1181C1: connectionHandlingThread (cs104_slave.c:2442)
==3374== by 0x11AB1F: destroyAutomaticThread (thread_linux.c:87)
==3374== by 0x4861D2F: start_thread (pthread_create.c:479)
==3374== by 0x4A8B07B: ??? (clone.S:73)
==3374== Address 0x4b5e6ae is 2 bytes before a block of size 12 alloc'd
==3374== at 0x483FDE8: operator new(unsigned int) (vg_replace_malloc.c:338)
==3374== by 0x10A2A7: __gnu_cxx::new_allocator<std::_List_node<int> >::allocate(unsigned int, void const*) (in /home/moxa/source/Rus_test_can_del/program)
==3374==
==3374== Conditional jump or move depends on uninitialised value(s)
==3374== at 0x1160F6: MessageQueue_setWaitingForTransmissionWhenNotConfirmed (cs104_slave.c:364)
==3374== by 0x117FEB: CS104_Slave_removeConnection (cs104_slave.c:2353)
==3374== by 0x1181C1: connectionHandlingThread (cs104_slave.c:2442)
==3374== by 0x11AB1F: destroyAutomaticThread (thread_linux.c:87)
==3374== by 0x4861D2F: start_thread (pthread_create.c:479)
==3374== by 0x4A8B07B: ??? (clone.S:73)
==3374== Uninitialised value was created by a heap allocation
==3374== at 0x483F5F8: malloc (vg_replace_malloc.c:309)
==3374== by 0x4A362BD: _IO_file_doallocate (filedoalloc.c:101)
==3374== by 0x4A4079B: _IO_doallocbuf (genops.c:347)
==3374== by 0x4A3FF0F: _IO_file_overflow@@GLIBC_2.4 (fileops.c:749)
==3374== by 0x4A3F4A5: _IO_new_file_xsputn (fileops.c:1248)
==3374== by 0x4A3F4A5: _IO_file_xsputn@@GLIBC_2.4 (fileops.c:1201)
==3374== by 0x4A37EF3: puts (ioputs.c:40)
==3374== by 0x109915: main (in /home/moxa/source/Rus_test_can_del/program)
==3374==
==3374== Use of uninitialised value of size 4
==3374== at 0x4845704: memcpy (vg_replace_strmem.c:1036)
==3374== by 0x11613B: MessageQueue_setWaitingForTransmissionWhenNotConfirmed (cs104_slave.c:376)
==3374== by 0x117FEB: CS104_Slave_removeConnection (cs104_slave.c:2353)
==3374== by 0x1181C1: connectionHandlingThread (cs104_slave.c:2442)
==3374== by 0x11AB1F: destroyAutomaticThread (thread_linux.c:87)
==3374== by 0x4861D2F: start_thread (pthread_create.c:479)
==3374== by 0x4A8B07B: ??? (clone.S:73)
==3374== Uninitialised value was created by a stack allocation
==3374== at 0x115DE6: MessageQueue_enqueueASDU (cs104_slave.c:190)
==3374== Conditional jump or move depends on uninitialised value(s)
==3374== at 0x4845714: memcpy (vg_replace_strmem.c:1036)
==3374== by 0x11613B: MessageQueue_setWaitingForTransmissionWhenNotConfirmed (cs104_slave.c:376)
==3374== by 0x117FEB: CS104_Slave_removeConnection (cs104_slave.c:2353)
==3374== by 0x1181C1: connectionHandlingThread (cs104_slave.c:2442)
==3374== by 0x11AB1F: destroyAutomaticThread (thread_linux.c:87)
==3374== by 0x4861D2F: start_thread (pthread_create.c:479)
==3374== by 0x4A8B07B: ??? (clone.S:73)
==3374== Uninitialised value was created by a stack allocation
==3374== at 0x115DE6: MessageQueue_enqueueASDU (cs104_slave.c:190)
==3374==
==3374== Use of uninitialised value of size 4
==3374== at 0x4845610: memcpy (vg_replace_strmem.c:1036)
==3374== by 0x11613B: MessageQueue_setWaitingForTransmissionWhenNotConfirmed (cs104_slave.c:376)
==3374== by 0x117FEB: CS104_Slave_removeConnection (cs104_slave.c:2353)
==3374== by 0x1181C1: connectionHandlingThread (cs104_slave.c:2442)
==3374== by 0x11AB1F: destroyAutomaticThread (thread_linux.c:87)
==3374== by 0x4861D2F: start_thread (pthread_create.c:479)
==3374== by 0x4A8B07B: ??? (clone.S:73)
==3374== Uninitialised value was created by a stack allocation
==3374== at 0x115DE6: MessageQueue_enqueueASDU (cs104_slave.c:190)
==3374==
==3374== Conditional jump or move depends on uninitialised value(s)
==3374== at 0x4845640: memcpy (vg_replace_strmem.c:1036)
==3374== by 0x11613B: MessageQueue_setWaitingForTransmissionWhenNotConfirmed (cs104_slave.c:376)
==3374== by 0x117FEB: CS104_Slave_removeConnection (cs104_slave.c:2353)
==3374== by 0x1181C1: connectionHandlingThread (cs104_slave.c:2442)
==3374== by 0x11AB1F: destroyAutomaticThread (thread_linux.c:87)
==3374== by 0x4861D2F: start_thread (pthread_create.c:479)
==3374== by 0x4A8B07B: ??? (clone.S:73)
==3374== Uninitialised value was created by a stack allocation
==3374== at 0x115DE6: MessageQueue_enqueueASDU (cs104_slave.c:190)
==3374==
==3374== Use of uninitialised value of size 4
==3374== at 0x48456D0: memcpy (vg_replace_strmem.c:1036)
==3374== by 0x11613B: MessageQueue_setWaitingForTransmissionWhenNotConfirmed (cs104_slave.c:376)
==3374== by 0x117FEB: CS104_Slave_removeConnection (cs104_slave.c:2353)
==3374== by 0x1181C1: connectionHandlingThread (cs104_slave.c:2442)
==3374== by 0x11AB1F: destroyAutomaticThread (thread_linux.c:87)
==3374== by 0x4861D2F: start_thread (pthread_create.c:479)
==3374== by 0x4A8B07B: ??? (clone.S:73)
==3374== Uninitialised value was created by a stack allocation
==3374== at 0x115DE6: MessageQueue_enqueueASDU (cs104_slave.c:190)
==3374==
==3374== Conditional jump or move depends on uninitialised value(s)
==3374== at 0x48456E0: memcpy (vg_replace_strmem.c:1036)
==3374== by 0x11613B: MessageQueue_setWaitingForTransmissionWhenNotConfirmed (cs104_slave.c:376)
==3374== by 0x117FEB: CS104_Slave_removeConnection (cs104_slave.c:2353)
==3374== by 0x1181C1: connectionHandlingThread (cs104_slave.c:2442)
==3374== by 0x11AB1F: destroyAutomaticThread (thread_linux.c:87)
==3374== by 0x4861D2F: start_thread (pthread_create.c:479)
==3374== by 0x4A8B07B: ??? (clone.S:73)
==3374== Uninitialised value was created by a stack allocation
==3374== at 0x115DE6: MessageQueue_enqueueASDU (cs104_slave.c:190)
==3374==
start change value function
==3374==
==3374== Process terminating with default action of signal 11 (SIGSEGV)
==3374== Bad permissions for mapped region at address 0x4F5102A
==3374== at 0x48456D0: memcpy (vg_replace_strmem.c:1036)
==3374== by 0x11613B: MessageQueue_setWaitingForTransmissionWhenNotConfirmed (cs104_slave.c:376)
==3374== by 0x117FEB: CS104_Slave_removeConnection (cs104_slave.c:2353)
==3374== by 0x1181C1: connectionHandlingThread (cs104_slave.c:2442)
==3374== by 0x11AB1F: destroyAutomaticThread (thread_linux.c:87)
==3374== by 0x4861D2F: start_thread (pthread_create.c:479)
==3374== by 0x4A8B07B: ??? (clone.S:73)
==3374==
==3374== HEAP SUMMARY:
==3374== in use at exit: 59,972 bytes in 936 blocks
==3374== total heap usage: 2,364 allocs, 1,428 frees, 239,400 bytes allocated
==3374== LEAK SUMMARY:
==3374== definitely lost: 0 bytes in 0 blocks
==3374== indirectly lost: 0 bytes in 0 blocks
==3374== possibly lost: 288 bytes in 2 blocks
==3374== still reachable: 59,684 bytes in 934 blocks
==3374== suppressed: 0 bytes in 0 blocks
==3374==
==3374== For lists of detected and suppressed errors, rerun with: -s
==3374== ERROR SUMMARY: 4187297 errors from 41 contexts (suppressed: 0 from 0)
Segmentation fault
最佳答案
您需要一一检查错误并修复它们。取第一个错误
==3374== Invalid read of size 1
==3374== at 0x4845704: memcpy (vg_replace_strmem.c:1036)
==3374== by 0x116063: MessageQueue_getNextWaitingASDU (cs104_slave.c:332)
==3374== by 0x117C75: sendNextLowPriorityASDU (cs104_slave.c:2180)
==3374== by 0x117DC9: sendWaitingASDUs (cs104_slave.c:2258)
==3374== by 0x11816B: connectionHandlingThread (cs104_slave.c:2431)
==3374== by 0x11AB1F: destroyAutomaticThread (thread_linux.c:87)
==3374== by 0x4861D2F: start_thread (pthread_create.c:479)
==3374== by 0x4A8B07B: ??? (clone.S:73)
==3374== Address 0x4b5b0b8 is 0 bytes after a block of size 13,600 alloc'd
==3374== at 0x4842290: calloc (vg_replace_malloc.c:762)
==3374== by 0x11AD0B: Memory_calloc (lib_memory.c:56)
==3374== by 0x115D25: MessageQueue_initialize (cs104_slave.c:128)
==3374== by 0x115D75: MessageQueue_create (cs104_slave.c:149)
==3374== by 0x1168B7: initializeMessageQueues (cs104_slave.c:1066)
==3374== by 0x118EAB: CS104_Slave_start (cs104_slave.c:3217)
==3374== by 0x10A33B: IEC60870::IEC60870(int, int, char const*, CS104_ServerMode) (in /home/moxa/source/Rus_test_can_del/program)
==3374== Address 0x4b5b0b8 is 0 bytes after a block of size 13,600 alloc'd
==3374== at 0x4842290: calloc (vg_replace_malloc.c:762)
calloc
的函数以便 Valgrind 可以跟踪内存分配。您可以忽略此行。
==3374== by 0x11AD0B: Memory_calloc (lib_memory.c:56)
calloc
.同样,您可能可以忽略这一点。
==3374== by 0x115D25: MessageQueue_initialize (cs104_slave.c:128)
==3374== Invalid read of size 1
char
或
bool
(
char
考虑到错误的以下部分)。
==3374== at 0x4845704: memcpy (vg_replace_strmem.c:1036)
==3374== by 0x116063: MessageQueue_getNextWaitingASDU (cs104_slave.c:332)
// allocate 10 items, with indexes 0 to 9
mem = new int[10];
for (int i = 0 i <= 10; ++i)
// but access **11** items from 0 to 10 inclusive
do something with mem[i]
nul
的字符串操作特点// inputString contains "hello" which is 6 bytes long (5 letters plus nul)
// but strlen doesn't count the nul so returns 5
len = strlen(inputString);
// allocate an array of 5 characters
copyString = (char*)malloc(len);
// copies 6 characters into a 5 character array!
memcpy(copyString, inputString, len+1);
关于c++ - 我的服务器中的段错误(valgrind 日志),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60960363/
谁能解释一下 Server.MapPath(".")、Server.MapPath("~")、Server.MapPath(@"之间的区别\") 和 Server.MapPath("/")? 最佳答案
我不知道,为什么我们要使用 Server.UrlEncode() & Server.UrlDecode()?!在 QueryString 中我们看到 URL 中的任何内容,那么为什么我们要对它们进行编
我已经通过 WHM 在我的一个域上安装了 ssl 证书。网站正在使用 https://xyz.com . 但是它不适用于 https://www.xyz.com .我已经检查了证书,它也适用于 www
我已经使用 WMI 检测操作系统上是否存在防病毒软件,itz 正常工作并通过使用命名空间向我显示防病毒信息,例如 win xp 和 window7 上的名称和实例 ID:\root\SecurityC
我们有 hive 0.10 版本,我们想知道是否应该使用 Hive Server 1 或 Hive Server2。另一个问题是连接到在端口 10000 上运行的 Hive 服务器,使用 3rd 方工
我想在 C++ 中使用 Windows Server API 设置一个 HTTPS 服务器,我使用了示例代码,它在 HTTP 上工作正常,但我就是不能让它在 HTTPS 上工作。 (我不想要客户端 S
我写了一个非常基本的类来发送电子邮件。我用 smtp 服务器对其进行了测试,它工作正常,但是当我尝试使用我公司的交换服务器时,它给出了这个异常: SMTP 服务器需要安全连接或客户端未通过身份验证。服
我的应用程序包含一个“网关”DataSnap REST 服务器,它是所有客户端的第一个访问点。根据客户端在请求中传递的用户名(基本身份验证),请求需要重定向到另一个 DataSnap 服务器。我的问题
我有一个 Tomcat 服务器和一个 Glassfish4 服务器。我的 Servlet 在 Tomcat 服务器上启动得很好,但在 Glassfish4 服务器上给我一个“HTTP Status 4
我在 vmware 上创建了一个 ubuntu 服务器。我用它作为文件服务器。如果我通过托管虚拟机的计算机进行连接,则可以访问它。我无法从同一网络上的其他计算机执行此操作。提前致谢! 最佳答案 首先确
如何重启 Rails 服务器?我从 开始 rails server -d 所以服务器是分离的 我知道的唯一方法就是去做ps 辅助 | grep rails 并 kill -9关于过程#但是像这样杀死进
我实际上正在尝试找到编写一个简单的 XMPP 服务器的最佳方法,或者找到一个占用空间非常小的服务器。我只关心XMPP的核心功能(状态、消息传递、群组消息传递)。目前还在学习 XMPP 协议(proto
我实际上正在尝试找到编写简单 XMPP 服务器的最佳方法,或者找到一个占用空间非常小的方法。我只关心 XMPP 的核心功能(统计、消息、组消息)。目前也在学习 XMPP 协议(protocol),所以
我们正在尝试从 Java JAX-RS 适配器访问 SOAP 1.1 Web 服务。 我们正在使用从 WSDL 生成的 SOAP 客户端。 但是当解码 SOAP 故障时,我们得到以下异常: ... C
目前,我和许多其他人正在多个平台(Windows、OS X 和可能的 Linux)上使用 Python HTTP 服务器。我们正在使用 Python HTTP 服务器来测试 JavaScript 游戏
我有一个连续运行的服务器程序(C#/.NET 2.0 on Linux with mono),我想从 PHP 脚本连接到它以在网站上显示状态信息。 目的是创建一个(某种)实时浏览器游戏(无 Flash
所以我有一个单页客户端应用程序。 正常流程: 应用程序 -> OAuth2 服务器 -> 应用程序 我们有自己的 OAuth2 服务器,因此人们可以登录应用程序并获取与用户实体关联的 access_t
我们刚刚将测试 Web 服务器从 Server 2008 升级到 Server 2012 R2。我们有一个部署我们网站的批处理脚本。当它将站点推送到服务器时,它现在失败了。奇怪的是,我可以使用相同的发
建议一些加载SpagoBI服务器的方法,我尝试了所有方法来解析spagobi服务器。在 Catalina 中,错误是 - * SEVERE: Unable to process Jar entry [
当我们点击应用程序服务器(apache tomcat)时,它会创建一个线程来处理我们的请求并与 tomcat 连接,建立连接,tomcat 创建另一个线程来处理请求并将其传递给连接,连接线程将其传递给
我是一名优秀的程序员,十分优秀!