Questions tagged [memset]
memset is a C standard library function that sets the first N bytes of the block of memory to the specified value (interpreted as an unsigned char)
486
questions
0
votes
2
answers
55
views
memset with math class macros
I am trying to use memset with INFINITY or NAN present in C header file <math.h>
My code is:
double *dist;
dist = (double *)malloc(7*sizeof(double));
memset(dist, INFINITY, 7*sizeof(dist[0]));
...
0
votes
1
answer
28
views
Fastest way to fill complex matrix with incoming data. Armadillo Library
I have situation where each 1ms is coming new buffer of 2*200 samples of int16_t. (multiplied by 2 is because complex data)
Those data should be added into Armadillo Complex Double Matrix, in the ...
0
votes
0
answers
38
views
memset() doesn't initialize a dynamic array correctly
I have a matrix class and there is a constructor like this:
// m is the 2d array "T **m", r = no. of rows and c = no. of coumns
matrix<T>(int r, int c, T v = T()) : r(r), c(c) {
m =...
2
votes
3
answers
134
views
How to properly solve memset() function MISRA errors in C?
I have written a simple function to initialise the structure values using memset(). These are the code I have written in C language.
myfile.h
typedef struct{
bool flag;
bool check;
int val_1;
int ...
0
votes
1
answer
33
views
C: check if an array element is empty after zero-out using memset
I am trying to zero out an array element and check its status so it won't be used again, however, it seems doesn't work.
int main(int argc, char const *argv[]){
char pid[10][20] = {"abc", &...
0
votes
0
answers
44
views
Does Dead Store Elimination work on class member variables in the Destructor?
I'm aware that DSE is a problem for crypto developers who primarily use C, particularly with the reliance on memset. However, would the same be true if a class zeroes out its member variables within ...
1
vote
2
answers
90
views
Properly initialise a struct in C++, specifically addrinfo
I am wondering how I can properly initialise a struct in a "C++-way".
I am filling an addrinfo-structure with the relevant information for my hints (to use in getaddrinfo()).
Depending on ...
0
votes
1
answer
38
views
Why does memset print different value when it's set to non zero? [duplicate]
I am trying to understand memset and pointer to an array. Below is my program and when I set the array contents 0 the value of *(p+6) prints 0.
But when I set the value to 5 *(p+6) it prints 84215045
...
0
votes
0
answers
26
views
Is it possible to securly remove a variable and its contents out of memory in PHP?
I am looking for a way to remove a variable and its contents out of ram securly within PHP. I know its possible in C/C++ and of course in underlying assembler. In C/C++/Asm so long as you don't copy ...
0
votes
0
answers
9
views
memcpy stores more than I set
The packet always is filled up at the end of file reading. Even though the data is less than 256 bytes, packet fills with data from previous line..
unsigned char packet[PacketSize]; // PacketSize is ...
1
vote
1
answer
14
views
3rd argument is ignored when I use memcpy in C
I'm a beginner in C and try to use memcpy to send byte in order to transfer data to server. It seems like no matter what I choose for 3rd argument. It's always the same.
#include <stdio.h>
#...
0
votes
0
answers
36
views
memset and static array declaration vs malloc [duplicate]
Malloc is used for dynamic memory allocation. However, this code doesn't use malloc, but is dynamic. In what case would I use malloc? Or is this code doing something really bad?
Sometimes, I see this ...
0
votes
0
answers
42
views
why is memset returning strange numbers when used with allocated arrays? [duplicate]
I'm trying to assign a value to an allocated array in c using memset, but it's returning strange numbers.
I looked at similar questions and googled for the answer but nothing seems to work.
here's my ...
0
votes
0
answers
14
views
memset crash in iOS
unsigned char output [keylen];
memset(&output, 0, keylen*sizeof(unsigned char));
When keylen >= 1019233, memory bad access and crash in iOS.
keylen < 1019233, everything works fine
0
votes
1
answer
55
views
what is `__GI_memset`? why does it cost so much CPU resource?
I'm new to perf, and I'm trying to use it to analyse my programme.
and I got this when running perf top:
PerfTop: 296 irqs/sec kernel:62.8% exact: 0.0% [1000Hz cycles:ppp], (all, 6 CPUs)
-----...
1
vote
1
answer
98
views
How to improve code around flawfinder memset warning?
In my code, all calls to memset appear as warnings with the flawfinder tool.
In the simplest case it could boil down to the equivalent to
float f1;
float f2;
void* p1 = &f1;
void* ...
0
votes
0
answers
63
views
QEMU "GPU" NUMA Node settings
when I install Nvidia CUDA Toolkit on a bare-metal host system with 2 CPU sockets and 4 GPUs the NUMA setting looks like this:
numactl --hardware
available: 6 nodes (0,8,252-255)
[...]
where:
0 and ...
24
votes
3
answers
704
views
When is memset to 0 nonportable? [duplicate]
From this comment in GCC bug #53119:
In C, {0} is the universal zero initializer equivalent to C++'s {} (the latter being invalid in C). It is necessary to use whenever you want a zero-initialized ...
2
votes
2
answers
73
views
Not being printed out when using fgets
I'm learning about file input/output in C. But there is something I don't understand.
I was about to print the simple sentence in the [words.txt] using fgets, but it doesn't work.
[words.txt] as below:...
0
votes
1
answer
167
views
Check if a struct is empty [duplicate]
I have an old piece of code with a big struct that looks like this:
typedef struct {
long test1;
char test2[10]
…
} teststruct;
This struct gets initialized like this:
memset(teststruct, 0, sizeof(...
1
vote
2
answers
497
views
bare metal embedded c++: undefined reference to memcpy and memset while writing flash to ram
As the tittle suggest, I'm getting an error related to not defining memcpy and memset, even though I'm not directly using it (although I guess it is used for the linker and compiling process given the ...
0
votes
1
answer
105
views
stack corruption detected when use memset in c++ from JNI Android
I am developing an Android application using C++ native code.
I have C++ code (XTTEA Algorithm in C++ native) which perfectly runs online with C++ compiler and I can get the output, but when I try to ...
2
votes
1
answer
70
views
Strange characters in String C
I was writing a simple compiler just for fun and I wanted each line to have proper indentation.
So I wrote a function that returns an array of characters with some white-spaces depending on the number....
4
votes
0
answers
131
views
nlohmann json: securely erase the keys (C++)
I'm using nlohmann/json library to represent sensitive information. Once the needed processing has been completed, I'm interested in securely erasing the keys of the json type.
Example:
json test;
...
0
votes
1
answer
228
views
Is this the correct way to use memset() in C? [closed]
So to start out I am a noob with C and am learning memory manipulation. I have a buffer that is called void* buffer. I then want to put an integer into the first 4 bytes of that buffer (since an int ...
0
votes
2
answers
199
views
Memset function and bool arrays
I was trying to learn about memset function and I read an article that we cannot initialise int array to 1 using memset. But I have declared a bool array and initialised it to true using memset ...
1
vote
1
answer
200
views
Measure memory write bandwidth using C
I'm trying to measure the write bandwidth of my memory, I created an 8G char array, and call memset on it with 128 threads. Below is the code snippet.
#include <stdio.h>
#include <stdlib.h>...
0
votes
3
answers
157
views
Fill 2D std::array of uint16_t in C++
I have a matrix in C++ defined as a std::array of std::array that I would like to set uniformly to a given value. I can't find something as simple as C-style memset for C-Style array (int a[10][10] ...
0
votes
1
answer
172
views
Memset too slow on large data. Any alternatives?
I have a large cv::Mat with dimensions (100,32768). I update it for every frame in a video stream. Before updating, I need to set everything back to zero so I execute
memset(myMat.data,0,100*32768*...
6
votes
2
answers
318
views
C++ placement new after memset
Suppose there's a struct whose constructor does not initialize all member variables:
struct Foo {
int x;
Foo() {}
}
If I memset some buffer to 0, use placement new on that buffer to create an ...
0
votes
1
answer
122
views
Why memset works wrong in apple clang compiler?
I found something strange doing problem solving with c++.
Initializing an integer array with loop works nice, but initializing it with memset function works wrong.
Below is the sample program.
#...
0
votes
5
answers
202
views
What is the fastest way to initialize an array in C with only two bytes for all elements?
Assume that we have an array called:
uint8_t data_8_bit[2] = {color >> 8, color & 0xff};
The data is 16-bit color data. Our goal is to create an array called:
uint8_t data_16_bit[2*n];
...
0
votes
0
answers
34
views
Weird Android native crash caused by memset
there is a crash happend in libc.so, and I have no idea:
crash msg:
signal 11 code 1 at address 0x10826c
crash stack:
#0 pc 0x505f0 /apex/com.android.runtime/lib/bionic/libc.so
source code:
22 ...
-1
votes
2
answers
107
views
using memset and freeaddrinfo causes the double free or corruption error
src.cpp
#include <iostream>
#include <cstring>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
int main(){
struct addrinfo hints, *servinfo;
...
-2
votes
1
answer
131
views
Does C++ memset only works for 0 and -1? [closed]
int a[2];
memset(a, 3, sizeof(a));
when I run this I am getting output as 0 1. Why not 3 3
4
votes
1
answer
111
views
GCC: Zeroing a struct
Why does gcc create different assembly code for the following functions to zero out a struct?
typedef struct {
char a;
int b;
} A;
void f(A *x) {
memset(x, 0, sizeof(*x));
}
void g(A *x) ...
0
votes
2
answers
75
views
How can I transform a pointer to the type I input in C++?
I have a question here:
I want to generate a type_t pointer (type_t *), pointing to a memory block, with specified value stored in it.
In another word, its input is:
string value,
string type
and its ...
0
votes
1
answer
91
views
Isn't these two operations the same thing in C++?
I have declared a 2D array of type bool and I want to initiate it with false. I have this requirement for a purpose of this code (given below) which is a question on "Wild Card String Matching&...
0
votes
2
answers
210
views
C - pass reference to pointer to function for malloc?
I am trying to pass a pointer reference (double) to a function, and inside the function I want to allocate memory to that pointer and fill it up with 10s. In Visual Studio both in x64 and x86 it doesn'...
2
votes
1
answer
565
views
SError kernel panic when memset_io'ing on device-tree memory area in Petalinux kernel module
My Platform: ZynQ MP; PetaLinux 2020.2
Build system: Ubuntu 18.04
I'm writing a Kernel module which registers itself as a platform_device with compatible string 'erika' with the PetaLinux Kernel on ...
0
votes
3
answers
292
views
Using memset with uninitialized variables
Is this valid C code without undefined behaviour?
int main(){
int a;
memset(&a, 5, sizeof(int));
return a;
}
I'm assuming this is equal to just doing int a = 5.
I'm trying to understand if ...
0
votes
2
answers
77
views
Memset function in C initialised all the arrays
I was trying to initialise a array made by pointer:
the code I used was:
int c = 15;
Struct *Pointer[c] = {NULL};
memset( pointer, 0, c *sizeof(pointer) );
It worked, But this memset() ...
37
votes
2
answers
1k
views
How to provide an implementation of memcpy
I am trying to write some bare metal code with a memset-style loop in it:
for (int i = 0; i < N; ++i) {
arr[i] = 0;
}
It is compiled with GCC and GCC is smart enough to turn that into a call to ...
0
votes
1
answer
347
views
memset() vulnerability [closed]
I am using memset in an embedded application to delete one data. here is the function:
uint8_t Delete()
{
memset(cure.name, 0x0, 32);
cure.volume = 0;
cure.valid=0;
printf("[*...
1
vote
0
answers
194
views
Why memset does not work for vector of bool? [duplicate]
I was doing some problem in which I required to reset values in a vector of bool after some searching I found out that memset() is faster than fill() so I tried to use it like this:
vector<bool>...
0
votes
1
answer
54
views
Is there any performance advantage of initialising an integer array with memset instead of default zero initialisation like array[10]={0}?
Given that memset can be only used to initialise an integer array with the values 0 or -1 what would be the reason that you use it for zero initialisation. Does its efficacy lie solely in string ...
0
votes
2
answers
115
views
Use memset for 2d array at specific row
recently, I have learnt about C++. Specially, I learned about memset function. But I don't know how to set value for 2d array at specific row
Example:
int dp[10][10];
// I want to set all values for ...
2
votes
2
answers
493
views
Program crash on memset?
I am struggling with memset.
If I write in my array my program crashes. If I comment out the memset i have no problems.
My type struct:
typedef struct
{
char Frage [maxLEN_F_A];
char ...
2
votes
1
answer
575
views
Implementation of memset to set a whole word instead of byte by byte in C
So I'm trying to implement my personal MemSet that will do the same as memset but also:
Copy word size chunks when possible, instead of byte by byte.
Guarantee dest's alignment
Test for all ...
0
votes
3
answers
2k
views
error clearing an object of non-trivial type with memset
Well, the thing is simple, im getting
warning: ‘void* memset(void*, int, size_t)’ clearing an object of non-trivial type ‘struct FormatHashBuffers(CBlock*, char*, char*, char*)::<unnamed>’; use ...