Member Avatar

I have this simple program in which I want to concatenate two char pointers using memcpy, but I get access violation writing location on the memcpy line. Why is this happening and what could be done to make it work? Thanks. char *first = new char[20], *second="world!"; printf("first: "); scanf("%s",&first); memcpy(first,second,strlen(second)+1); printf ("Result: %s, %d \n", first);

Member Avatar
+0 forum 4
Member Avatar

What is the maximum buffer size allowed in memecpy() function in c, I am using GCC compiler,32-bit system, What is the affecting factor for memcpy failure? ->Alignment issue? ->Size? however the buffer size 256bytes not working, tried 160 bytes copy which fits our requirement

Member Avatar
+0 forum 8
Member Avatar

Hi. Nice to meet you. I'd like to know if I'm doing the allocation of memory from data to new_data correctly and why new_data only has one value since the memory of data was copied before to new_data. set size: 10 set[000] = 000 set[001] = 001 set[002] = 002 set[003] = 003 set[004] = 004 set[005] = 005 set[006] = 006 set[007] = 007 set[008] = 008 set[009] = 009 set size: 1 set[000] = 009 ==3827== ==3827== HEAP SUMMARY: ==3827== in use at exit: 40 bytes in 1 blocks ==3827== total heap usage: 22 allocs, 21 frees, 256 …

Member Avatar
+0 forum 2
Member Avatar

I used `memcpy` to copy the contents of one pointer to another pointer assigned to new memory. Later in the program I get runtime errors as if I were attempting to operate on a pointer pointing to nothing. While debugging, I saw that the original and the the copied pointer had different addresses but they acted as if they were one, for example If I set a property of the copied pointer to 'a' the original would also get set to 'a'. In this case I delete the copied pointer and the original gets deleted too as if they pointed …

Member Avatar
+0 forum 4
Member Avatar

I have been working on a few projects and needed a method similar to pythons string.split(). I decided to make a reusable piece of code and export it as a .dll, the code is below: std::vector<std::string> Editor::StringHandler::Split(std::string data, std::string tokens) std::vector<std::string> returnList; std::string temp=""; bool found=false; for (auto i : data) { found = false; for (auto token : tokens) { found = (i == token); if (found && temp.length() > 0) { returnList.push_back(temp); temp = ""; } if (found) { break; } } if (!found) { temp += i; } } if (!found) { returnList.push_back(temp); } return returnList; } …

Member Avatar
+0 forum 13
Member Avatar

Hi all, I am currently extending a large C project with an own extension and I am stuck in a pointer/array/struct problem: The project offers a struct of this structure [CODE]struct ip_addr{ unsigned int af; /* address family: AF_INET6 or AF_INET */ unsigned int len; /* address len, 16 or 4 */ /* 64 bits aligned address */ union { unsigned long addrl[16/sizeof(long)]; /* long format*/ unsigned int addr32[4]; unsigned short addr16[8]; unsigned char addr[16]; }u; };[/CODE] I can access the addr32 of a messages-IP-address by calling [ICODE]msg->rcv.src_ip.u.addr32[/ICODE] Now, I want to copy the content of the this ip_addr-struct into …

Member Avatar
+0 forum 1
Member Avatar

I am writing a video program, everything works fine except I am often (ie most times, but not [I]every [/I]time) getting the following error: Unhandled exception at 0x6076fde0 (msvcr90d.dll) in javaw.exe: 0xC0000005: Access violation reading location 0x0a450020. I have tracked it down to this function: [CODE]//fill the buffer from data void TFrame::WriteBuffer(unsigned char *ucBuffer){ if (PixelBuffer != NULL) { if ( ucBuffer != NULL) { if (PixelBufferSize != NULL) { //the error doesnt occour when this line is commented out memcpy (PixelBuffer,ucBuffer,PixelBufferSize); } } } }[/CODE] I start a thread to capture the video. The exception only happens when I …

Member Avatar
+0 forum 4
Member Avatar

Hi, the code analysis tool we use gives below warning for the functions in which memset / memcpy is used "The function writes outside the bounds of dup on line 303, which could corrupt data, cause the program to crash, or lead to the execution of malicious code." could someone please help remove this warning. Thanks.

Member Avatar
+0 forum 5

The End.