Menu
  • HOME
  • TAGS

how does this even compile

c,arrays,pointers,memset

THe first version (LocRunTimeInfo[LabelId]) is missing the address operator: &LocRunTimeInfo[LabelId] would be correct. Without that, it returns struct mpls_RuntimeInfo_s, not the required pointer to it. LocRunTimeInfo + LabelId is also correct, as that is identical to the correct version. The text in the standard shows getting the entry itself, but...

aio_write and memset invalid argument and Segmentation Fault (core dumped)

c,segmentation-fault,memset,invalid-argument

If you want to set each byte of aiorp to the ASCII value of 'a', your first varaiant: memset((void *) aiorp, 'a', sizeof(struct aiocb)); is good. (You don't need the cast to void *, though, and could rewrite the size to sizeof(*aiorp) to follow a common pattern.) But why do...

How to initialize arrays in 2 ways using loop and memset?

c,arrays,function,memset

A few points to help you get started: You're trying to set all items to 0. Scanf requires you to input all values. This isn't necessary as you could just set them to 0 with data[count]=0.0f; inside of that for loop. memset is a function that will do something similar...

memset() in C not initialising to a const double;

c,memset

memset initializes a block of memory with a given byte value. Bytes are unsigned char, a much smaller unit than double which uses 8 bytes on your architecture. Unless all the bytes of the double value C are identical, memset cannot be used to initialize an array of double values....

c pointer for struct causes segment fault while doing

c,pointers,memset

Because your pointer is not initialized, maybe you mean ircsend1_struct irpack; char *pBuffer = &irpack; memset(pBuffer, 0, sizeof(ircsend1_struct)); ...

OS X memset and system trace

c,osx,instruments,memset

For security and privacy purposes, the kernel needs to guarantee that pages that are newly allocated to a process are filled with zeroes. Otherwise, you could get data from some other process, including, for example, passwords or financial information. The pages are zeroed on first access, sort of similar to...

Confustion with realpath() buffer [duplicate]

c,linked-list,memset,realpath

In List_push(list, buf); you store a pointer to buf in the list. You do this for each file, so you end up with several pointers to the same buf in the list. When printing the list items it then will show the (current) contents of buf. To avoid this you...

I want to use memset to remove some characters from string

c,arrays,string,pointers,memset

The problem here is, path points to a string literal, which is usually present in read-only memory. You may not change the content of that. Instead, try using an array like char path[ ] = "tt/tt/tt/text.txt"; ...

Erasing sensitive information from memory

c,security,memset

The example you have provided is not quite valid: the compiler can optimize out a variable setting operation when it can detect that there are no side effects and the value is no longer used. So, if your code uses some shared buffer, accessible from multiple locations, the memset would...

Mutex assertion error with non-zero heap

c,pthreads,mutex,heap-memory,memset

OK, the solution is silly. I simply didn't initialize the mutex. The reason I didn't think of this was that the above code worked fine with calloc(). I guess omitting initialization will backfire when you least expect it. From manpages: The pthread_mutex_init() function shall initialize the mutex referenced by mutex...

memset does not work (C)

c,memset

memset(visited,0,2500);//reset Visited is an array of integers, so this should be memset(visited, 0, 2500 * sizeof(int)) ...

memset() to initialize object in constructor?

c++,constructor,initialization,memset

There is no advantage in using memset() like this. Leaving behind all the obvious disadvantages and future pain, there is one disadvantage that makes it less efficient than Message() : a(0), b(0), c(0) {} This is because PODs are usually stored in arrays. So good (smart) compiler will have an...

C++ Receiving 2 or more UDP Messages at same time

c++,sockets,udp,memset

I figured it is because the socket is everytime the method is called in the infinite loop, the getUdp() method opens a socket, gets the message and closes the socket, resulting in the server not being able to queue the messages. Your intuition is correct. When you have a...

Why does invalid memset() after malloc() leads to free(): invalid next size (fast) [duplicate]

c,memory,free,memcpy,memset

A typical dynamic memory (heap) implementation stores a lot of household information right there, in the very same memory, interleaved with user data. Each block of memory you allocate typically includes a special header region and, possibly, a special footer region. These regions surround your user region from both ends....

c memset function puzzle [duplicate]

c,memset

They accomplish the same thing. buf evaluates to a pointer to the first element (int*) of the array, while &buf gets you a pointer-to-array-of-8-int*s. (The types differ in a somewhat obscure way.) Both of those pointers can be used to access the byte representation of the array via casting to...

c++ memset cause segment fault of int** pointer

c++,arrays,memset

The arrays dpTable[i] do not point to contiguous memory. You have to initialize then one by one for (int i = 0; i < iMatrixHeight + 1; i++) { dpTable[i] = new int [iMatrixWidth + 1]; memset(dpTable[i], 0, (iMatrixWidth + 1) * sizeof(int)) ; } ...

Malloc Memset is this usage right ?

c++,malloc,memset,static-cast

sizeof(buffer) is returning you the size of void* (the size of a void pointer). Which has nothing to do with the size of memory block. The size of void* is commonly 4 or 8 bytes, but this depends on the platform. So memset() is only clearing a few bytes in...

Error with pointers. Invalid type argument of unary *

c,pointers,memset

cbloc is a pointer to characters, so in DFORC, ptr is also a pointer to characters. The statement: printf("'%c', ", *ptr[counter]); First uses ptr as an array, accessing element counter of that array. This returns a char (not a char *). You then try to dereference that char, which is...

c++ unsigned char array allocation - segmentation fault

c,segmentation-fault,malloc,memset,unsigned-char

It seems that your program is written in C instead of C++. In C++ you should use operator new [] instead of malloc. The problem with the function is that function parameters are its local variables. So the function parameter char *data is a copy of its argument declared in...

How memset initializes an array of integers by -1?

c++,c,arrays,twos-complement,memset

Oddly, the reason this works with -1 is exactly the same as the reason that this works with zeros: in two's complement binary representation, -1 has 1s in all its bits, regardless of the size of the integer, so filling in a region with bytes filled with all 1s produces...

implicit conversion changes signedness 'int“ to 'unsigned int”

c++,implicit-conversion,memset

Replace grid_ = new int[x_quadrants * y_quadrants]; memset(grid_, 0, sizeof(int) * x_quadrants * y_quadrants); with just grid_ = new int[x_quadrants * y_quadrants](); Note the parenthesis, that tells the compiler you want this zero-initialized (or really value-initialization, which reduces to zero-initialization here). Even better, use a std::vector instead of this dangerous...

Do I need to memset a C struct in Swift?

c,swift,struct,memset

From the Xcode 6.3 release notes: Imported C structs now have a default initializer in Swift that initializes all of the struct's fields to zero. which means that var hints = addrinfo() initializes all fields of struct addrinfo to zero and there is no need to call memset()....