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
ac9fb499
Commit
ac9fb499
authored
Apr 21, 2011
by
Pieter Noordhuis
Browse files
Don't abort on OOM in sds.c
parent
75bc8595
Changes
1
Show whitespace changes
Inline
Side-by-side
sds.c
View file @
ac9fb499
...
@@ -28,18 +28,18 @@
...
@@ -28,18 +28,18 @@
* POSSIBILITY OF SUCH DAMAGE.
* POSSIBILITY OF SUCH DAMAGE.
*/
*/
#define SDS_ABORT_ON_OOM
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <ctype.h>
#include <ctype.h>
#include "sds.h"
#include "sds.h"
#ifdef SDS_ABORT_ON_OOM
static
void
sdsOomAbort
(
void
)
{
static
void
sdsOomAbort
(
void
)
{
fprintf
(
stderr
,
"SDS: Out Of Memory (SDS_ABORT_ON_OOM defined)
\n
"
);
fprintf
(
stderr
,
"SDS: Out Of Memory (SDS_ABORT_ON_OOM defined)
\n
"
);
abort
();
abort
();
}
}
#endif
sds
sdsnewlen
(
const
void
*
init
,
size_t
initlen
)
{
sds
sdsnewlen
(
const
void
*
init
,
size_t
initlen
)
{
struct
sdshdr
*
sh
;
struct
sdshdr
*
sh
;
...
@@ -378,6 +378,8 @@ sds sdsfromlonglong(long long value) {
...
@@ -378,6 +378,8 @@ sds sdsfromlonglong(long long value) {
sds
sdscatrepr
(
sds
s
,
char
*
p
,
size_t
len
)
{
sds
sdscatrepr
(
sds
s
,
char
*
p
,
size_t
len
)
{
s
=
sdscatlen
(
s
,
"
\"
"
,
1
);
s
=
sdscatlen
(
s
,
"
\"
"
,
1
);
if
(
s
==
NULL
)
return
NULL
;
while
(
len
--
)
{
while
(
len
--
)
{
switch
(
*
p
)
{
switch
(
*
p
)
{
case
'\\'
:
case
'\\'
:
...
@@ -397,6 +399,7 @@ sds sdscatrepr(sds s, char *p, size_t len) {
...
@@ -397,6 +399,7 @@ sds sdscatrepr(sds s, char *p, size_t len) {
break
;
break
;
}
}
p
++
;
p
++
;
if
(
s
==
NULL
)
return
NULL
;
}
}
return
sdscatlen
(
s
,
"
\"
"
,
1
);
return
sdscatlen
(
s
,
"
\"
"
,
1
);
}
}
...
@@ -416,7 +419,7 @@ sds sdscatrepr(sds s, char *p, size_t len) {
...
@@ -416,7 +419,7 @@ sds sdscatrepr(sds s, char *p, size_t len) {
sds
*
sdssplitargs
(
char
*
line
,
int
*
argc
)
{
sds
*
sdssplitargs
(
char
*
line
,
int
*
argc
)
{
char
*
p
=
line
;
char
*
p
=
line
;
char
*
current
=
NULL
;
char
*
current
=
NULL
;
char
**
vector
=
NULL
;
char
**
vector
=
NULL
,
**
_vector
=
NULL
;
*
argc
=
0
;
*
argc
=
0
;
while
(
1
)
{
while
(
1
)
{
...
@@ -427,7 +430,11 @@ sds *sdssplitargs(char *line, int *argc) {
...
@@ -427,7 +430,11 @@ sds *sdssplitargs(char *line, int *argc) {
int
inq
=
0
;
/* set to 1 if we are in "quotes" */
int
inq
=
0
;
/* set to 1 if we are in "quotes" */
int
done
=
0
;
int
done
=
0
;
if
(
current
==
NULL
)
current
=
sdsempty
();
if
(
current
==
NULL
)
{
current
=
sdsempty
();
if
(
current
==
NULL
)
goto
err
;
}
while
(
!
done
)
{
while
(
!
done
)
{
if
(
inq
)
{
if
(
inq
)
{
if
(
*
p
==
'\\'
&&
*
(
p
+
1
))
{
if
(
*
p
==
'\\'
&&
*
(
p
+
1
))
{
...
@@ -471,9 +478,13 @@ sds *sdssplitargs(char *line, int *argc) {
...
@@ -471,9 +478,13 @@ sds *sdssplitargs(char *line, int *argc) {
}
}
}
}
if
(
*
p
)
p
++
;
if
(
*
p
)
p
++
;
if
(
current
==
NULL
)
goto
err
;
}
}
/* add the token to the vector */
/* add the token to the vector */
vector
=
realloc
(
vector
,((
*
argc
)
+
1
)
*
sizeof
(
char
*
));
_vector
=
realloc
(
vector
,((
*
argc
)
+
1
)
*
sizeof
(
char
*
));
if
(
_vector
==
NULL
)
goto
err
;
vector
=
_vector
;
vector
[
*
argc
]
=
current
;
vector
[
*
argc
]
=
current
;
(
*
argc
)
++
;
(
*
argc
)
++
;
current
=
NULL
;
current
=
NULL
;
...
@@ -485,8 +496,8 @@ sds *sdssplitargs(char *line, int *argc) {
...
@@ -485,8 +496,8 @@ sds *sdssplitargs(char *line, int *argc) {
err:
err:
while
((
*
argc
)
--
)
while
((
*
argc
)
--
)
sdsfree
(
vector
[
*
argc
]);
sdsfree
(
vector
[
*
argc
]);
free
(
vector
);
if
(
vector
!=
NULL
)
free
(
vector
);
if
(
current
)
sdsfree
(
current
);
if
(
current
!=
NULL
)
sdsfree
(
current
);
return
NULL
;
return
NULL
;
}
}
...
...
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