Questions tagged [memcmp]

memcmp is a function available in the string.h library.

Official Definition

The memcmp() function compares the first n bytes (each interpreted as unsigned char) of the memory areas s1 and s2.

Syntax of usage

#include <string.h>
int memcmp(const void *s1, const void *s2, size_t n);

Source

Linux Man Pages

106 questions
1
vote
2 answers

Why do I get a Segmentation fault? I'm using stat, mmap, nftw, and memcmp, among other things

Here is my code. I'm assuming this has something to do with improper use of pointers or maybe I'm not mapping and unmapping my memory correctly. Could anyone please provide me with some insight into the issue? #define _XOPEN_SOURCE 500 #include…
Frank
  • 155
  • 1
  • 2
  • 9
1
vote
1 answer

netfilter hook function memory reference crashed my system

please look at the code snippet char ipAddr[] = {192, 168, 88, 2}; struct iphdr *ip_hdr = (struct iphdr*)(some_valid_eth_hdr_pointer + 1); if (0 == memcmp((void*)(ip_hdr->saddr), (void*)ipAddr, 4)) /*memcmp cause my whole system crashed*/ { …
Tracy
  • 1,988
  • 5
  • 25
  • 36
0
votes
3 answers

Best way to compare sha1 hashes for equality

I want to compare two sha1 hashes for equality. What could be the most efficient way to do this? Currently, I am trying using memcmp. Thanks.
polapts
  • 5,493
  • 10
  • 37
  • 49
0
votes
0 answers

Same endian machines but different outputs

I have a piece of code and its generating different output when run on centOS and RHEL systems and both are little-endian machines. RHEL: result is 0 Cent OS: result is -4 #include #include typedef unsigned short U16; typedef…
user3899508
  • 35
  • 2
  • 7
0
votes
1 answer

Merit of signed comparison return of memcmp

What is a merit for the signed int return value of memcmp compared to say bool? I don't think I've ever used the return value of memcmp other than to compare it against zero.
foreverska
  • 585
  • 3
  • 20
0
votes
0 answers

memcmp difference between gcc 10.3 and gcc 11.1 for char16_t

Im converting some tests that use the memcmp function and don't get the expected output. Now I've been trying to figure out why there is a difference in the windows vs linux output and I ended up on godbolt.org. There I played around with different…
Gert Kommer
  • 1,163
  • 2
  • 22
  • 49
0
votes
1 answer

Why memcmp return int

I read about int vs size_t vs ssize_t , and I understand that int and ssize_t is signed while size_t is unsigned. Why memcmp return int and no return ssize_t like recv return ssize_t?
yfr24493AzzrggAcom
  • 159
  • 1
  • 2
  • 13
0
votes
1 answer

Compare two doubles to see if they are the same NaN

I have two doubles x and y with y known to be a particular NaN value, I'd like to see if they are bitwise identical. That is, I want to determine if x is exactly the same NaN value as y. NaNs cannot be usefully compared with the == opeator since…
BeeOnRope
  • 60,350
  • 16
  • 207
  • 386
0
votes
3 answers

What exactly does memcmp return?

I am trying to create my own memcmp file but whenever I compare it with original memcmp function the equal strings return zero but in case of unequal strings return values are different. char *p = (char *)s1; char *q = (char *)s2; int…
0
votes
3 answers

Comparing integers with memcmp()

I am making a function to get the maximum value of an array of NMEMB members each one of size SIZ, comparing each member with memcmp(). The problem is that when comparing signed integers the result is incorrect but at the same time correct. Here is…
dlb04
  • 27
  • 1
  • 7
0
votes
0 answers

static_assert failed: size of struct is not the same as sum of sizes of all properties

I'm new to C++ languages and I'm writing a data structure which will be used to serialize/deserialize data saved on local machine. The code data structure looks like this: struct DerMeasurementData { float DerAnalogMeasValue = 0.0; int…
0
votes
0 answers

C - occasional CPU stall during memcmp on Cortex-R5

I'm running some tests on a Cortex-R5 (Ultrascale MpSoC). It basically generates 2 random numbers with a hardware module and compares them at the end to ensure they're not 0, nor the same values. uint32_t status; const uint8_t zeros[32] =…
Floha
  • 1
0
votes
3 answers

how to add validation mr or mrs before name

I'm doing validation to input name using Mr or ms or Mrs before name with do while statement. what should I fill in the while section?. is it using strcmp or something else? coding example do{ printf("Input Customer's Name [must have Mr. or Ms.…
Abr
  • 35
  • 5
0
votes
0 answers

Using memcmp with DOS far pointers

I have an old program I wrote in 1995. It is written with Borland C and DOS 6.22. It uses a far model with data in different segments. The program uses EMS memory and that is why the pointers need to be far. I need to use memcmp( a, b, c) but I get…
Aabbee
  • 91
  • 6
0
votes
1 answer

Why do memcmp implementation not shortcut memcmp(q, p, n) for the case where q==p?

If I pass memcmp the equal pointers for its first and second argument, I suspected that it might just return 0 without checking the elements -- since if the same pointer is passed the elements must be zero. It seems like to me it is good…
Frames Catherine White
  • 27,368
  • 21
  • 87
  • 137