Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpim-sw
libcdi
Commits
a79be7d1
Commit
a79be7d1
authored
Mar 03, 2014
by
Thomas Jahns
🤸
Browse files
Fix omissions for checksumming on big-endian platforms.
parent
5e55420e
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/cksum.c
View file @
a79be7d1
#include <inttypes.h>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#include <sys/types.h>
...
...
@@ -108,18 +112,18 @@ memcrc_r(uint32_t *state, const unsigned char *block, size_t block_len)
*
state
=
s
;
}
#define SWAP_CSUM(BITWIDTH,BYTEWIDTH) \
do { \
for (size
_t
i
=
num_elems; i > 0; --i) {
\
{
\
uint##BITWIDTH##_t accum =
*(uint##BITWIDTH##_t *)b++;
\
for (j = 0; j < BYTEWIDTH; ++j)
\
{ \
uint32_t c = (uint32_t)(accum & UCHAR_MAX); \
s = (s << 8) ^ crctab[(s >> 24) ^ c]; \
accum >>= 8; \
} \
} \
#define SWAP_CSUM(BITWIDTH,BYTEWIDTH)
\
do {
\
register const uint##BITWIDTH##
_t
*b
=
(uint##BITWIDTH##_t *)elems;
\
for (size_t i = 0; i < num_elems; ++i) {
\
uint##BITWIDTH##_t accum =
b[i];
\
for (
size_t
j = 0; j < BYTEWIDTH; ++j) \
{
\
uint32_t c = (uint32_t)(accum & UCHAR_MAX);
\
s = (s << 8) ^ crctab[(s >> 24) ^ c];
\
accum >>= 8;
\
}
\
}
\
} while (0)
...
...
@@ -136,14 +140,13 @@ memcrc_r_eswap(uint32_t *state, const unsigned char *elems, size_t num_elems,
size_t
elem_size
)
{
#ifdef WORDS_BIGENDIAN
register
uint32_t
c
,
s
=
*
state
;
register
size_t
n
=
block_len
;
register
unsigned
char
*
b
=
elems
;
register
uint32_t
s
=
*
state
;
switch
(
elem_size
)
{
case
1
:
return
memcrc_r
(
state
,
elems
,
num_elems
,
elem_size
);
memcrc_r
(
state
,
elems
,
num_elems
*
elem_size
);
return
;
case
2
:
SWAP_CSUM
(
16
,
2
);
break
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment