Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
b84186ff
Commit
b84186ff
authored
Jun 01, 2010
by
Pieter Noordhuis
Browse files
fix signedness errors in ziplist testing code
parent
6ddc908a
Changes
1
Hide whitespace changes
Inline
Side-by-side
ziplist.c
View file @
b84186ff
...
@@ -584,10 +584,10 @@ void ziplistRepr(unsigned char *zl) {
...
@@ -584,10 +584,10 @@ void ziplistRepr(unsigned char *zl) {
unsigned
char
*
createList
()
{
unsigned
char
*
createList
()
{
unsigned
char
*
zl
=
ziplistNew
();
unsigned
char
*
zl
=
ziplistNew
();
zl
=
ziplistPush
(
zl
,
"foo"
,
3
,
ZIPLIST_TAIL
);
zl
=
ziplistPush
(
zl
,
(
unsigned
char
*
)
"foo"
,
3
,
ZIPLIST_TAIL
);
zl
=
ziplistPush
(
zl
,
"quux"
,
4
,
ZIPLIST_TAIL
);
zl
=
ziplistPush
(
zl
,
(
unsigned
char
*
)
"quux"
,
4
,
ZIPLIST_TAIL
);
zl
=
ziplistPush
(
zl
,
"hello"
,
5
,
ZIPLIST_HEAD
);
zl
=
ziplistPush
(
zl
,
(
unsigned
char
*
)
"hello"
,
5
,
ZIPLIST_HEAD
);
zl
=
ziplistPush
(
zl
,
"1024"
,
4
,
ZIPLIST_TAIL
);
zl
=
ziplistPush
(
zl
,
(
unsigned
char
*
)
"1024"
,
4
,
ZIPLIST_TAIL
);
return
zl
;
return
zl
;
}
}
...
@@ -596,23 +596,23 @@ unsigned char *createIntList() {
...
@@ -596,23 +596,23 @@ unsigned char *createIntList() {
char
buf
[
32
];
char
buf
[
32
];
sprintf
(
buf
,
"100"
);
sprintf
(
buf
,
"100"
);
zl
=
ziplistPush
(
zl
,
buf
,
strlen
(
buf
),
ZIPLIST_TAIL
);
zl
=
ziplistPush
(
zl
,
(
unsigned
char
*
)
buf
,
strlen
(
buf
),
ZIPLIST_TAIL
);
sprintf
(
buf
,
"128000"
);
sprintf
(
buf
,
"128000"
);
zl
=
ziplistPush
(
zl
,
buf
,
strlen
(
buf
),
ZIPLIST_TAIL
);
zl
=
ziplistPush
(
zl
,
(
unsigned
char
*
)
buf
,
strlen
(
buf
),
ZIPLIST_TAIL
);
sprintf
(
buf
,
"-100"
);
sprintf
(
buf
,
"-100"
);
zl
=
ziplistPush
(
zl
,
buf
,
strlen
(
buf
),
ZIPLIST_HEAD
);
zl
=
ziplistPush
(
zl
,
(
unsigned
char
*
)
buf
,
strlen
(
buf
),
ZIPLIST_HEAD
);
sprintf
(
buf
,
"4294967296"
);
sprintf
(
buf
,
"4294967296"
);
zl
=
ziplistPush
(
zl
,
buf
,
strlen
(
buf
),
ZIPLIST_HEAD
);
zl
=
ziplistPush
(
zl
,
(
unsigned
char
*
)
buf
,
strlen
(
buf
),
ZIPLIST_HEAD
);
sprintf
(
buf
,
"non integer"
);
sprintf
(
buf
,
"non integer"
);
zl
=
ziplistPush
(
zl
,
buf
,
strlen
(
buf
),
ZIPLIST_TAIL
);
zl
=
ziplistPush
(
zl
,
(
unsigned
char
*
)
buf
,
strlen
(
buf
),
ZIPLIST_TAIL
);
sprintf
(
buf
,
"much much longer non integer"
);
sprintf
(
buf
,
"much much longer non integer"
);
zl
=
ziplistPush
(
zl
,
buf
,
strlen
(
buf
),
ZIPLIST_TAIL
);
zl
=
ziplistPush
(
zl
,
(
unsigned
char
*
)
buf
,
strlen
(
buf
),
ZIPLIST_TAIL
);
return
zl
;
return
zl
;
}
}
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
unsigned
char
*
zl
,
*
p
;
unsigned
char
*
zl
,
*
p
;
char
*
entry
;
unsigned
char
*
entry
;
unsigned
int
elen
;
unsigned
int
elen
;
long
long
value
;
long
long
value
;
sds
s
;
sds
s
;
...
@@ -852,19 +852,19 @@ int main(int argc, char **argv) {
...
@@ -852,19 +852,19 @@ int main(int argc, char **argv) {
printf
(
"Delete foo while iterating:
\n
"
);
printf
(
"Delete foo while iterating:
\n
"
);
{
{
zl
=
createList
();
zl
=
createList
();
p
=
ziplistIndex
(
zl
,
0
);
p
=
ziplistIndex
(
zl
,
0
);
while
(
ziplistGet
(
p
,
&
entry
,
&
elen
,
&
value
))
{
while
(
ziplistGet
(
p
,
&
entry
,
&
elen
,
&
value
))
{
if
(
entry
&&
strncmp
(
"foo"
,
entry
,
elen
)
==
0
)
{
if
(
entry
&&
strncmp
(
"foo"
,
(
char
*
)
entry
,
elen
)
==
0
)
{
printf
(
"Delete foo
\n
"
);
printf
(
"Delete foo
\n
"
);
zl
=
ziplistDelete
(
zl
,
&
p
,
ZIPLIST_TAIL
);
zl
=
ziplistDelete
(
zl
,
&
p
);
}
else
{
}
else
{
printf
(
"Entry: "
);
printf
(
"Entry: "
);
if
(
entry
)
{
if
(
entry
)
{
fwrite
(
entry
,
elen
,
1
,
stdout
);
fwrite
(
entry
,
elen
,
1
,
stdout
);
}
else
{
}
else
{
printf
(
"%lld"
,
value
);
printf
(
"%lld"
,
value
);
}
}
p
=
ziplistNext
(
p
);
p
=
ziplistNext
(
zl
,
p
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
}
}
}
}
...
@@ -879,7 +879,7 @@ int main(int argc, char **argv) {
...
@@ -879,7 +879,7 @@ int main(int argc, char **argv) {
int
i
,
len
;
int
i
,
len
;
for
(
i
=
0
;
i
<
1000
;
i
++
)
{
for
(
i
=
0
;
i
<
1000
;
i
++
)
{
len
=
sprintf
(
buf
,
"%d"
,
i
);
len
=
sprintf
(
buf
,
"%d"
,
i
);
zl
=
ziplistPush
(
zl
,
buf
,
len
,
ZIPLIST_TAIL
);
zl
=
ziplistPush
(
zl
,
(
unsigned
char
*
)
buf
,
len
,
ZIPLIST_TAIL
);
}
}
for
(
i
=
0
;
i
<
1000
;
i
++
)
{
for
(
i
=
0
;
i
<
1000
;
i
++
)
{
p
=
ziplistIndex
(
zl
,
i
);
p
=
ziplistIndex
(
zl
,
i
);
...
@@ -896,22 +896,22 @@ int main(int argc, char **argv) {
...
@@ -896,22 +896,22 @@ int main(int argc, char **argv) {
printf
(
"Compare strings with ziplist entries:
\n
"
);
printf
(
"Compare strings with ziplist entries:
\n
"
);
{
{
zl
=
createList
();
zl
=
createList
();
p
=
ziplistIndex
(
zl
,
0
);
p
=
ziplistIndex
(
zl
,
0
);
if
(
!
ziplistCompare
(
p
,
"hello"
,
5
))
{
if
(
!
ziplistCompare
(
p
,
(
unsigned
char
*
)
"hello"
,
5
))
{
printf
(
"ERROR: not
\"
hello
\"\n
"
);
printf
(
"ERROR: not
\"
hello
\"\n
"
);
return
1
;
return
1
;
}
}
if
(
ziplistCompare
(
p
,
"hella"
,
5
))
{
if
(
ziplistCompare
(
p
,
(
unsigned
char
*
)
"hella"
,
5
))
{
printf
(
"ERROR:
\"
hella
\"\n
"
);
printf
(
"ERROR:
\"
hella
\"\n
"
);
return
1
;
return
1
;
}
}
p
=
ziplistIndex
(
zl
,
3
);
p
=
ziplistIndex
(
zl
,
3
);
if
(
!
ziplistCompare
(
p
,
"1024"
,
4
))
{
if
(
!
ziplistCompare
(
p
,
(
unsigned
char
*
)
"1024"
,
4
))
{
printf
(
"ERROR: not
\"
1024
\"\n
"
);
printf
(
"ERROR: not
\"
1024
\"\n
"
);
return
1
;
return
1
;
}
}
if
(
ziplistCompare
(
p
,
"1025"
,
4
))
{
if
(
ziplistCompare
(
p
,
(
unsigned
char
*
)
"1025"
,
4
))
{
printf
(
"ERROR:
\"
1025
\"\n
"
);
printf
(
"ERROR:
\"
1025
\"\n
"
);
return
1
;
return
1
;
}
}
...
...
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