English 中文(简体)
阀门-无效书写尺寸
原标题:valgrind - invalid write size

我们有一起使用共同记忆的C份申请。 第一项申请增加了信息,第二项总是从共享记忆中读取。

struct messagestruct {
 unsigned int sessionid;
 uint8_t message[16]; //unsigned 8bit int
}__attribute__ ((__packed__));

我们需要举行3次会议(供3名用户使用)。 定义的共有记忆体

#define SHARED_SIZE ( 3 *  sizeof(messagestruct)) + sizeof(int)

我们获得共同记忆

int sesskey = ftok("/path/to/a/file", "B");
int shmemoryid = shmget(sesskey, SHARED_SIZE, 0666 | IPC_CREAT);    

在复制用于共享记忆的建筑时,对流星报告错误(无效书写尺寸1)

void *shmaddr = shmat(shmemoryid, NULL, 0);
int *sessnum;
struct messagestruct *msgstruct;
sessnum = (int *)shmaddr;
msgstruct = (struct messagestruct*)((void*) shmaddr + sizeof(int));   
memcpy(shmaddr, currentsessionsstruct, SHARED_SIZE); //-->valgrind error invalid write size 1

thanks for any helpful info.

最佳回答
memcpy(shmaddr, currentsessionsstruct, SHARED_SIZE);

You are copying 3 * sizeof(messagestruct) + sizeof(int). I believe you want to copy only sizeof(currentsessionstruct).

问题回答

暂无回答




相关问题
CGImage create thumbnail image with desired size

I want to create the thumbnail using the CG. It creates the thumbnails. Here i want to have the thumbnail with the size 1024 (with aspect ratio.) Is it possible to get the desired size thumbnail ...

How to get the size of an image in bytes with Delphi?

my app has 3 controls: TThumbnailList (image viewer from TMS components), TImage, and TLabel. I wish that when I drag an image from TThumbnailList to TImage, and drop it, the TLabel object shows the ...

Determine total size of SVN directory/trunk

Is there a way to count/calculate the total size of a svn directory if you were to checkout a revision? I have limited internet downloads so I need to know how big something is before I go and ...

SharePoint - Approaching Website Storage Limit Email

How can i go about changing the distribution list as well as the email text for the email that goes out to site collection admin when a site collection approaches it s size limit? Thanks for your ...

Size of reference of an class in JAVA

What is the size of reference of a class in Java? Is it constant for a particular JVM and OS irrespective of the class for which the reference is made. Class A Class B Class C A a; B b; C c; Are ...

MPLAB IDE data type sizes

In MPLAB IDE what is the sizes of data types (int, unsigned int, float, unsigned float, char...)?

热门标签