Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
9fc013b2
Commit
9fc013b2
authored
Mar 31, 2009
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New test and fixes to crcsync.
parent
4df5a75f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
2 deletions
+101
-2
ccan/crcsync/crcsync.c
ccan/crcsync/crcsync.c
+8
-2
ccan/crcsync/test/run-crash.c
ccan/crcsync/test/run-crash.c
+93
-0
No files found.
ccan/crcsync/crcsync.c
View file @
9fc013b2
...
...
@@ -192,6 +192,10 @@ size_t crc_read_block(struct crc_context *ctx, long *result,
if
(
ctx
->
literal_bytes
>
ctx
->
block_size
)
{
*
result
=
ctx
->
literal_bytes
-
ctx
->
block_size
;
ctx
->
literal_bytes
-=
*
result
;
/* Advance buffer. */
if
(
*
result
>=
buffer_size
(
ctx
))
ctx
->
buffer_start
=
ctx
->
buffer_end
=
0
;
else
ctx
->
buffer_start
+=
*
result
;
}
else
*
result
=
0
;
...
...
@@ -206,7 +210,9 @@ size_t crc_read_block(struct crc_context *ctx, long *result,
ctx
->
buffer_end
-=
ctx
->
buffer_start
;
ctx
->
buffer_start
=
0
;
}
memcpy
(
ctx
->
buffer
+
ctx
->
buffer_end
,
buf
,
len
);
/* Copy len bytes from tail of buffer. */
memcpy
(
ctx
->
buffer
+
ctx
->
buffer_end
,
buf
+
buflen
-
len
,
len
);
ctx
->
buffer_end
+=
len
;
assert
(
buffer_size
(
ctx
)
<=
ctx
->
block_size
);
}
...
...
ccan/crcsync/test/run-crash.c
0 → 100644
View file @
9fc013b2
/* This used to crash us on 64-bit; submitted by
Alex Wulms <alex.wulms@scarlet.be> */
#include "crcsync/crcsync.h"
#include "crcsync/crcsync.c"
#include "tap/tap.h"
#include <stdlib.h>
#include <stdbool.h>
/* FIXME: ccanize. */
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
typedef
struct
{
int
block_count
;
unsigned
int
*
crcs
;
}
crc_info_t
;
static
void
crcblocks
(
crc_info_t
*
crc_info
,
char
*
data
,
int
datalen
,
int
blocksize
)
{
crc_info
->
block_count
=
(
datalen
+
blocksize
-
1
)
/
blocksize
;
crc_info
->
crcs
=
malloc
(
sizeof
(
unsigned
int
)
*
(
crc_info
->
block_count
+
1
));
crc_of_blocks
(
data
,
datalen
,
blocksize
,
30
,
crc_info
->
crcs
);
}
#define BLOCKSIZE 5
int
main
(
int
argc
,
char
*
argv
[])
{
/* Divided into BLOCKSIZE blocks */
char
*
data1
=
"abcde"
"fghij"
"klmno"
"pqrst"
"uvwxy"
"z ABC"
"DEFGH"
"IJKLM"
"NOPQR"
"STUVW"
"XYZ 0"
"12345"
"6789"
;
/* Divided into blocks that match. */
char
*
data2
=
/* NO MATCH */
"acde"
/* MATCH */
"fghij"
"klmno"
/* NO MATCH */
"pqr-a-very-long-test-that-differs-between-two-invokations-of-the-same-page-st"
/* MATCH */
"uvwxy"
"z ABC"
"DEFGH"
"IJKLM"
"NOPQR"
"STUVW"
"XYZ 0"
"12345"
/* NO MATCH */
"6789ab"
;
int
expected
[]
=
{
4
,
-
2
,
-
3
,
77
,
-
5
,
-
6
,
-
7
,
-
8
,
-
9
,
-
10
,
-
11
,
-
12
,
6
};
crc_info_t
crc_info1
;
struct
crc_context
*
crcctx
;
long
result
;
size_t
ndigested
;
size_t
offset
=
0
;
size_t
len2
=
strlen
(
data2
);
int
expected_i
=
0
;
plan_tests
(
ARRAY_SIZE
(
expected
)
+
2
);
crcblocks
(
&
crc_info1
,
data1
,
strlen
(
data1
),
BLOCKSIZE
);
crcctx
=
crc_context_new
(
BLOCKSIZE
,
30
,
crc_info1
.
crcs
,
crc_info1
.
block_count
);
while
(
offset
<
len2
)
{
ndigested
=
crc_read_block
(
crcctx
,
&
result
,
data2
+
offset
,
len2
-
offset
);
offset
+=
ndigested
;
if
(
result
<
0
)
/* Match. */
ok1
(
result
==
expected
[
expected_i
++
]);
else
{
/* Literal. */
ok1
(
result
<=
expected
[
expected_i
]);
expected
[
expected_i
]
-=
result
;
if
(
!
expected
[
expected_i
])
expected_i
++
;
}
}
while
((
result
=
crc_read_flush
(
crcctx
))
!=
0
)
{
if
(
result
<
0
)
/* Match. */
ok1
(
result
==
expected
[
expected_i
++
]);
else
{
/* Literal. */
ok1
(
result
<=
expected
[
expected_i
]);
expected
[
expected_i
]
-=
result
;
if
(
!
expected
[
expected_i
])
expected_i
++
;
}
}
ok1
(
expected_i
==
ARRAY_SIZE
(
expected
));
return
0
;
}
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