Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
cf68f4ee
R
redis
项目概览
xindoo
/
redis
通知
2
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cf68f4ee
编写于
7月 20, 2015
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix SDS type 5 sdsIncrLen() bug and added test.
Thanks to @oranagra for spotting this error.
上级
3da97ea6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
27 addition
and
15 deletion
+27
-15
src/sds.c
src/sds.c
+27
-15
未找到文件。
src/sds.c
浏览文件 @
cf68f4ee
...
...
@@ -305,8 +305,8 @@ void sdsIncrLen(sds s, int incr) {
unsigned
char
*
fp
=
((
unsigned
char
*
)
s
)
-
1
;
unsigned
char
oldlen
=
SDS_TYPE_5_LEN
(
flags
);
assert
((
incr
>
0
&&
oldlen
+
incr
<
32
)
||
(
incr
<
0
&&
oldlen
>=
(
unsigned
int
)(
-
incr
)));
*
fp
=
SDS_TYPE_5
|
((
oldlen
+
1
)
<<
SDS_TYPE_BITS
);
len
=
oldlen
+
1
;
*
fp
=
SDS_TYPE_5
|
((
oldlen
+
incr
)
<<
SDS_TYPE_BITS
);
len
=
oldlen
+
incr
;
break
;
}
case
SDS_TYPE_8
:
{
...
...
@@ -1193,28 +1193,40 @@ int sdsTest(void) {
test_cond
(
"sdscatrepr(...data...)"
,
memcmp
(
y
,
"
\"\\
a
\\
n
\\
x00foo
\\
r
\"
"
,
15
)
==
0
)
#if 0
{
unsigned
int
oldfree
;
char
*
p
;
int
step
=
10
,
j
,
i
;
sdsfree
(
x
);
sdsfree
(
y
);
x
=
sdsnew
(
"0"
);
sh = (void*) (x-(sizeof(struct sdshdr)));
test_cond("sdsnew() free/len buffers", sh->len == 1 && sh->free == 0);
x = sdsMakeRoomFor(x,1);
sh = (void*) (x-(sizeof(struct sdshdr)));
test_cond("sdsMakeRoomFor()", sh->len == 1 && sh->free > 0);
oldfree = sh->free;
x[1] = '1';
sdsIncrLen(x,1);
test_cond("sdsIncrLen() -- content", x[0] == '0' && x[1] == '1');
test_cond("sdsIncrLen() -- len", sh->len == 2);
test_cond("sdsIncrLen() -- free", sh->free == oldfree-1);
test_cond
(
"sdsnew() free/len buffers"
,
sdslen
(
x
)
==
1
&&
sdsavail
(
x
)
==
0
);
/* Run the test a few times in order to hit the first two
* SDS header types. */
for
(
i
=
0
;
i
<
10
;
i
++
)
{
int
oldlen
=
sdslen
(
x
);
x
=
sdsMakeRoomFor
(
x
,
step
);
int
type
=
x
[
-
1
]
&
SDS_TYPE_MASK
;
test_cond
(
"sdsMakeRoomFor() len"
,
sdslen
(
x
)
==
oldlen
);
if
(
type
!=
SDS_TYPE_5
)
{
test_cond
(
"sdsMakeRoomFor() free"
,
sdsavail
(
x
)
>=
step
);
oldfree
=
sdsavail
(
x
);
}
p
=
x
+
oldlen
;
for
(
j
=
0
;
j
<
step
;
j
++
)
{
p
[
j
]
=
'A'
+
j
;
}
sdsIncrLen
(
x
,
step
);
}
test_cond
(
"sdsMakeRoomFor() content"
,
memcmp
(
"0ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ"
,
x
,
101
)
==
0
);
test_cond
(
"sdsMakeRoomFor() final length"
,
sdslen
(
x
)
==
101
);
sdsfree
(
x
);
}
#endif
}
test_report
()
return
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录