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
hiredis
Commits
747d78be
Unverified
Commit
747d78be
authored
Sep 27, 2018
by
Mark Nunberg
Committed by
GitHub
Sep 27, 2018
Browse files
Merge pull request #580 from charsyam/feature/fix-realloc
fix common realloc mistake and add null check more
parents
273fae1d
471557c3
Changes
1
Show whitespace changes
Inline
Side-by-side
sds.c
View file @
747d78be
...
...
@@ -219,7 +219,10 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
hdrlen
=
sdsHdrSize
(
type
);
if
(
oldtype
==
type
)
{
newsh
=
s_realloc
(
sh
,
hdrlen
+
newlen
+
1
);
if
(
newsh
==
NULL
)
return
NULL
;
if
(
newsh
==
NULL
)
{
s_free
(
sh
);
return
NULL
;
}
s
=
(
char
*
)
newsh
+
hdrlen
;
}
else
{
/* Since the header size changes, need to move the string forward,
...
...
@@ -592,6 +595,7 @@ sds sdscatfmt(sds s, char const *fmt, ...) {
/* Make sure there is always space for at least 1 char. */
if
(
sdsavail
(
s
)
==
0
)
{
s
=
sdsMakeRoomFor
(
s
,
1
);
if
(
s
==
NULL
)
goto
fmt_error
;
}
switch
(
*
f
)
{
...
...
@@ -605,6 +609,7 @@ sds sdscatfmt(sds s, char const *fmt, ...) {
l
=
(
next
==
's'
)
?
strlen
(
str
)
:
sdslen
(
str
);
if
(
sdsavail
(
s
)
<
l
)
{
s
=
sdsMakeRoomFor
(
s
,
l
);
if
(
s
==
NULL
)
goto
fmt_error
;
}
memcpy
(
s
+
i
,
str
,
l
);
sdsinclen
(
s
,
l
);
...
...
@@ -621,6 +626,7 @@ sds sdscatfmt(sds s, char const *fmt, ...) {
l
=
sdsll2str
(
buf
,
num
);
if
(
sdsavail
(
s
)
<
l
)
{
s
=
sdsMakeRoomFor
(
s
,
l
);
if
(
s
==
NULL
)
goto
fmt_error
;
}
memcpy
(
s
+
i
,
buf
,
l
);
sdsinclen
(
s
,
l
);
...
...
@@ -638,6 +644,7 @@ sds sdscatfmt(sds s, char const *fmt, ...) {
l
=
sdsull2str
(
buf
,
unum
);
if
(
sdsavail
(
s
)
<
l
)
{
s
=
sdsMakeRoomFor
(
s
,
l
);
if
(
s
==
NULL
)
goto
fmt_error
;
}
memcpy
(
s
+
i
,
buf
,
l
);
sdsinclen
(
s
,
l
);
...
...
@@ -662,6 +669,10 @@ sds sdscatfmt(sds s, char const *fmt, ...) {
/* Add null-term */
s
[
i
]
=
'\0'
;
return
s
;
fmt_error:
va_end
(
ap
);
return
NULL
;
}
/* Remove the part of the string from left and from right composed just of
...
...
@@ -1018,10 +1029,18 @@ sds *sdssplitargs(const char *line, int *argc) {
if
(
*
p
)
p
++
;
}
/* add the token to the vector */
vector
=
s_realloc
(
vector
,((
*
argc
)
+
1
)
*
sizeof
(
char
*
));
{
char
**
new_vector
=
s_realloc
(
vector
,((
*
argc
)
+
1
)
*
sizeof
(
char
*
));
if
(
new_vector
==
NULL
)
{
s_free
(
vector
);
return
NULL
;
}
vector
=
new_vector
;
vector
[
*
argc
]
=
current
;
(
*
argc
)
++
;
current
=
NULL
;
}
}
else
{
/* Even on empty input string return something not NULL. */
if
(
vector
==
NULL
)
vector
=
s_malloc
(
sizeof
(
void
*
));
...
...
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