Questions tagged [memcpy]

memcpy() is a C standard library function used for copying a block of memory bytes from one place to another.

Synopsis

#include <string.h>

void *memcpy(void * restrict s1,
     const void * restrict s2,
     size_t n);

Description
The memcpy function copies n characters from the object pointed to by s2 into the object pointed to by s1. If copying takes place between objects that overlap, the behavior is undefined.

Returns
The memcpy function returns the value of s1.

1578 questions
0
votes
1 answer

CGBitmapContextGetData - can't copy data to the returned block of memory

I am drawing RGBA data onto the screen using CGBitmapContextCreate and CGContextDrawImage. When I try to create bitmapcontext using CGBitmapContextCreate(pixelBuffer,...) where I have alreadymalloc'ed pixelBuffer and placed my data there, this works…
R.S
  • 321
  • 3
  • 15
0
votes
5 answers

memcpy error on struct

I'm getting the following error with memcpy. It doesn't give compilation error but doesn't give the result I would imagine. I've never used memcpy before so I'm sure I'm making a simple mistake. I've looked around previous questions but couldn't…
0
votes
3 answers

How do you convert an unsigned int[16] of hexidecimal to an unsigned char array without losing any information?

I have a unsigned int[16] array that when printed out looks like this: 4418703544ED3F688AC208F53343AA59 The code used to print it out is this: for (i = 0; i < 16; i++) printf("%X", CipherBlock[i] / 16), printf("%X",CipherBlock[i] %…
user1068636
  • 1,871
  • 7
  • 33
  • 57
0
votes
1 answer

C++ error message: invalid pointer

I have a function to append a string to another string: char* strjoin(char* str1,const char* str2) { long len1 = strlen(str1); long len2 = strlen(str2); char* result = (char*)malloc(len1+len2+1); memcpy(result,str1,len1+1); …
jondinham
  • 8,271
  • 17
  • 80
  • 137
0
votes
1 answer

static struct variable segfaults

I have a structure allocated like so: static struct cparray_buffer_t *_cparray; struct __attribute__ ((__packed__)) cparray_buffer_t { u_int64_t buflen; u_char buf[buffersize]; } . . . _cparray = (struct cparray_buffer_t *)calloc(1024,…
Derek
  • 11,715
  • 32
  • 127
  • 228
0
votes
1 answer

Copy unsigned short with memcpy

I have a 'runtime error' when I try to copy the value of the variable 'b' into the variable 'a'. #include #include typedef struct{ unsigned short a; }st1; main() { st1* myStruct; unsigned short b =…
0
votes
2 answers

Array of strings in C++: Extra characters printed

I am having some trouble understanding this output for my code: #define MAX 5 char pipeNames[MAX][1024]; string s1 = "\\\\.\\p\\p1"; string s2 = "\\\\.\\p\\p2"; int len1 = strlen(s1.c_str()); int len2 =…
0
votes
2 answers

C++ - Buffer combining adding extra empty values

I am trying to fill two buffers, an index buffer object and a vertex buffer object in C++. // Create the IBO and VBO data GLushort* iboData = new GLushort[polyProcessed * 3]; Vertex* vboData = new Vertex[vertProcessed]; int iboPos = 0; int vboPos =…
Satchmo Brown
  • 1,409
  • 2
  • 20
  • 47
0
votes
1 answer

C++ Strange Crash with msvcr90.dll!memcpy

I am using 3rd party Decoder [ which is DivX] and in my application I get "A first chance exception of type 'System.AccessViolationException' occurred" When I look at stack trace, it seems that there is an error at memcpy in…
Novalis
  • 2,265
  • 6
  • 39
  • 63
0
votes
2 answers

Getting gibberish instead of numbers using memcpy and strtoul

I have the following piece of code compiling under gcc: int parseMsg(const char *msg_to_parse, unsigned long *exp_input, unsigned long *sysTicks ) { int l_msg_size = strlen(msg_to_parse); if(l_msg_size <10) return -1; char…
b3bel
  • 375
  • 1
  • 5
  • 15
0
votes
3 answers

memcpy Seg fault seemingly innoculous

Got a seg fault from my memcpy that gdb can't give me anything else on (at least beyond the simple manner that I know how to use gdb...). This thing is deeply imbedded in some code using the Berkely DB; I have taken out the only lines that should be…
levitopher
  • 117
  • 6
0
votes
2 answers

Handling memcpy segfaults when passed with invalid inputs in an attack scenario

I am testing a small issue with a daemon here (written in linux). I want to know whether what is done is right or not. The daemon loads a shared object file (.so) using dlopen call. The the shared object receives some buffers from clients over the…
Deaf Ear
  • 153
  • 12
0
votes
1 answer

Looking for code to benchmark C lib string and memory functions

I'm looking for existing code I can use to benchmark C lib memory and string functions like memcpy, memset, strcpy, strcmp, etc. I've done a google search and there are several hits for people who have done such benchmarking but everybody seems to…
0
votes
2 answers

Serializing Int values to char* buffer in ANSI C

I tried to serialize a structure field (int) to a char* buffer but I think I am doing things wrong. This is what I am using to copy this field. memcpy(payload + offset, &packet->payload.offset, sizeof(long int)); packet->payload.offset is a long int…
0
votes
3 answers

memcpy structure failed

I tried to memcpy measure_msg (struct test) to a buffer. However, the code below doesn't seems to copy the data. The value return **** ptr:0xb781c238 **** ptr:0xb781c23c **** ptr:0xb781c244 buff[0]=5 - buff[1]=0 - buff[2]=0 - buff[3]=0 - buff[4]=W -…
twfx
  • 1,664
  • 9
  • 29
  • 56