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
b36d1c30
Commit
b36d1c30
authored
May 20, 2010
by
Pieter Noordhuis
Browse files
fix lookup of keys with length larger than ZIPMAP_BIGLEN
parent
469c4e45
Changes
1
Hide whitespace changes
Inline
Side-by-side
zipmap.c
View file @
b36d1c30
...
...
@@ -136,14 +136,15 @@ static unsigned int zipmapEncodeLength(unsigned char *p, unsigned int len) {
* reallocate the original zipmap to make room for more entries. */
static
unsigned
char
*
zipmapLookupRaw
(
unsigned
char
*
zm
,
unsigned
char
*
key
,
unsigned
int
klen
,
unsigned
int
*
totlen
)
{
unsigned
char
*
p
=
zm
+
1
,
*
k
=
NULL
;
unsigned
int
l
;
unsigned
int
l
,
llen
;
while
(
*
p
!=
ZIPMAP_END
)
{
unsigned
char
free
;
/* Match or skip the key */
l
=
zipmapDecodeLength
(
p
);
if
(
k
==
NULL
&&
l
==
klen
&&
!
memcmp
(
p
+
1
,
key
,
l
))
{
llen
=
zipmapEncodeLength
(
NULL
,
l
);
if
(
k
==
NULL
&&
l
==
klen
&&
!
memcmp
(
p
+
llen
,
key
,
l
))
{
/* Only return when the user doesn't care
* for the total length of the zipmap. */
if
(
totlen
!=
NULL
)
{
...
...
@@ -152,7 +153,7 @@ static unsigned char *zipmapLookupRaw(unsigned char *zm, unsigned char *key, uns
return
p
;
}
}
p
+=
zipmapEncodeLength
(
NULL
,
l
)
+
l
;
p
+=
llen
+
l
;
/* Skip the value as well */
l
=
zipmapDecodeLength
(
p
);
p
+=
zipmapEncodeLength
(
NULL
,
l
);
...
...
@@ -403,7 +404,6 @@ int main(void) {
zm
=
zipmapSet
(
zm
,(
unsigned
char
*
)
"surname"
,
7
,
(
unsigned
char
*
)
"foo"
,
3
,
NULL
);
zm
=
zipmapSet
(
zm
,(
unsigned
char
*
)
"age"
,
3
,
(
unsigned
char
*
)
"foo"
,
3
,
NULL
);
zipmapRepr
(
zm
);
exit
(
1
);
zm
=
zipmapSet
(
zm
,(
unsigned
char
*
)
"hello"
,
5
,
(
unsigned
char
*
)
"world!"
,
6
,
NULL
);
zm
=
zipmapSet
(
zm
,(
unsigned
char
*
)
"foo"
,
3
,
(
unsigned
char
*
)
"bar"
,
3
,
NULL
);
...
...
@@ -416,6 +416,21 @@ int main(void) {
zipmapRepr
(
zm
);
zm
=
zipmapDel
(
zm
,(
unsigned
char
*
)
"new"
,
3
,
NULL
);
zipmapRepr
(
zm
);
printf
(
"
\n
Look up large key:
\n
"
);
{
unsigned
char
buf
[
512
];
unsigned
char
*
value
;
unsigned
int
vlen
,
i
;
for
(
i
=
0
;
i
<
512
;
i
++
)
buf
[
i
]
=
'a'
;
zm
=
zipmapSet
(
zm
,
buf
,
512
,(
unsigned
char
*
)
"long"
,
4
,
NULL
);
if
(
zipmapGet
(
zm
,
buf
,
512
,
&
value
,
&
vlen
))
{
printf
(
" <long key> is associated to the %d bytes value: %.*s
\n
"
,
vlen
,
vlen
,
value
);
}
}
printf
(
"
\n
Perform a direct lookup:
\n
"
);
{
unsigned
char
*
value
;
...
...
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